У меня есть сервис:
private publishSubscribeSubject_: ReplaySubject<any> = new ReplaySubject();
private emiter_: Observable<any>;
public publish(channel: EventsChannels, event: any) {
this.publishSubscribeSubject_.next({ channel: channel, event: event });
}
public subscribe(channel: EventsChannels[] | EventsChannels , handler: (value: any) => void) {
return this.emiter_
.filter(emission => emission.channel === channel)
.map(emission => emission.event)
.subscribe(handler);
}
Использование в компоненте:
ngOnInit() {
this.objectDetailsSubscription = this.eventService.subscribe(
EventsChannels.OBJECT_DETAILS,
semantic => {
console.log(semantic);
}
);
}
Почему каждый раз, когда я активирую компонент, я вижу все последние значения в ngOnInit() {}
с ReplaySubject
?
<app-object-details *ngIf="menuItemType === menuItemTypes.ObjectDetails"></app-object-details>