Angular2 detect change in service

Viewed 36376

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();
}
1 Answers
Related