This is a question about using the angular-l10n translation module, but since it's a more typescript specific question i post it here.
To dynamically configure the module (and for example set the default language), i have to use the following method:
load(): Function {
this.localeConfig.language = 'en';
return () => this.l10nLoader.load();
}
localeConfig and l10nLoader are both injected.
return () => this.l10nLoader.load(); has to be executed at the end to actually show the page after configuration.
What i would like to do is to load the language from an api and then set the configuration.
I do this in a service which returns an Observable and then subscribe to it inside of the load() function.
load(): Function {
this.languageService.getDefaultLanguage().subscribe(
lang => {
this.localeConfig.language = lang;
return ???
}
);
}
The problem is: I don't know how to return
this.l10nLoader.load();at the end of the subscription. If i return it at the end of the function it is done before the subscription ends.
How do i return something of type Function after the subscription is finished?
this.l10nLoader.load()in there rather than returning the same wrapped in an arrow function? Any value in returning it?load(): Function { this.localeConfig.language = 'en'; this.l10nLoader.load(); }without the return statement? I'm trying to understand the requirement for a higher order function here.