Lets say i have 2 fat arrow methods defined in the providers
array of @NgModule
. They are called capitalize
and capitalizeCallingMethod
.
@NgModule({
providers: [
{ provide: 'capitalize',
useValue: (stringToCapitalize : string) => {
if(stringToCapitalize && stringToCapitalize.length > 1)
return stringToCapitalize.charAt(0).toUpperCase() + stringToCapitalize.slice(1).toLowerCase();
else
return stringToCapitalize;
}
},
{ provide: 'capitalizeCallingMethod',
useValue: aString => {
return capitalize(aString); //How do i call capitalize?
}
}
]
});
Is it possible to call capitalize
from within capitalizeCallingMethod
and if so, how do i achieve this? I've already looked at similar questions on stackoverflow about providers calling providers but they are all about provider classes that use other provider classes.
For the
capitalizeCallingMethod
provider, replaceuseValue
withuseFactory
, and pass thecapitalize
token as a dependencyAn example of the format looks like