Sorry for my English. I have service that provide in main module. When did happen change this.userSettings
object using setSettings
method I want that all subscribers on userSettingsObservable
were called. Subscription happens in different components through call getSettingsObservable
method in this service.
constructor() {
this.userSettingsObservable = new Observable((observer: Observer<UserSettings>) => {
this.userSettingsObserver = observer;
});
}
getSettingsObservable() {
return this.userSettingsObservable;
}
setSettings(path: string) {
this.userSettings = _.set(this.userSettings, path, value);
this.userSettingsObserver.next(_.clone(this.userSettings));
}
Examples of subscription on Observable in component:
ngOnInit() {
this.userSettingsService.getSettingsObservable().subscribe(
(userSettings) => {
this.userSettings = userSettings;
}
);
}
In my case subscribe calling only on last subscribed component. How to make that subscribe calling in all components where I done subscribe?
Thanks!
P.S. You can see full code of service here: https://github.com/pakhuta/siarhei.pakhuta.angular2/blob/master/src/app/shared/user-settings.service.ts#L41
and subscription here: https://github.com/pakhuta/siarhei.pakhuta.angular2/blob/master/src/app/weather/weather.component.ts#L43