I have one component in Angular2 which is changing a "lang" class variable in my service translate.service.ts. In another component I am fetching a dict with the translation on init. If the first component changes the services language later, I want to refetch the dict in the second component automatically. How do I do that?
First component:
setLang(lang) {
this._translateService.setLang(lang);
}
Service:
dict = { "en": {}};
lang = "en";
setLang(lang) {
this.lang = lang;
}
getLang() {
return this.dict;
}
Second component:
ngOnInit() {
this.dict = this._translateService.getDict();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…