I'm puzzled by this rxjs tap() operator never firing in this simple Angular component, while the Subject value does get updated on the screen. I also tried using a BehaviorSubject instead with the same results. What I'm I doing wrong here?
import { Component } from '@angular/core';
import { Subject, BehaviorSubject } from 'rxjs';
import { tap } from 'rxjs/operators';
@Component({
selector: 'my-app',
template: '{{ selectedUserId | async }}',
})
export class AppComponent {
selectedUserId = new Subject<number>();
// selectedUserId = new BehaviorSubject<number>(0);
ngOnInit() {
this.selectedUserId
.pipe(
tap(id => console.log(id)) // why this is not logging to console?
);
setTimeout(() => this.selectedUserId.next(1), 1000);
//this.selectedUserId.next(1);
}
}