After creating an Observable from the array [1, 2, 3, 4, 5] and logging each iteration, the output is as expected: 1,2,3,4,5.
However, when adding shareReplay(2), only the last two iterations - 4,5 are displayed. This result is confusing as I was anticipating to see 1,2 as the output.
numbers$: Observable<number> = from([1, 2, 3, 4, 5, 6, 7]);
ngOnInit() {
this.numbers$.pipe(
shareReplay(2),
refCount()
).subscribe(data => console.log(data));
}
The issue can be seen on stackBlitz: https://stackblitz.com/edit/hello-angular-6-yb387t?file=src/app/app.component.ts