I am facing an issue where I have two subscribers to the same Observable, but the second one is not emitting any values. Could there be a limitation within the pipe that I am unaware of?
component.ts
private readonly destroyed$ = new Subject<void>();
public readonly vm$ = this.service.vm$.pipe(
tap(console.log),
takeUntil(this.destroyed$)
);
public readonly labels$ = this.service.vm$.pipe(
zip(this.makeLabels),
tap(console.log),
takeUntil(this.destroyed$)
)
...
constructor(private readonly service: SomeService) {
this.service.load();
}
ngOnDestroy(): void {
this.destroyed$.next();
this.destroyed$.complete();
}
some.service.ts
export class SomeService implements OnDestroy {
private readonly destroyed$ = new Subject<void>();
private _vm$ = new BehaviorSubject<ViewModel>(null);
public readonly vm$ = this._vm$.asObservable().pipe(takeUntil(this.destroyed$));
...
load() { this._vm$.next({...}) }
}
component.html
<ng-container *ngIf="vm$ | async as vm">
<header>
<pre *ngFor="let label of labels$ | async">
{{label | json}}
</pre>
</header>
</ng-container>