The problem is: when this.getPost())) return error eg 404 (it's function which return GET), then code this.loggedChange.emit(false)
is not executed and I don't know why. After this situation I have wrong output of loggedChangedHandler. It's look like inside error, after swtichMap, this.loggedChange has not 'observes'. Before switchMap it has observes so I think that it can be clue, but I don't know why it works like this. If first function return error (this.authLogin - it also retur get), then this.loggedChange.emit works fine.
child component:
login(): void {
this.authLogin(this.email, this.password)
.pipe(
tap(() => this.loggedChange.emit(true)),
switchMap(() => this.getPost())
)
.subscribe(
resp => {
//some code here
},
error => {
this.loggedChange.emit(false);
}
);
}
in parent component I have something like this:
<login-component (loggedChange)="loggedChangeHandler($event)"></login-component>
and in ts
loggedIn$ = new BehaviorSubject(false);
loggedChangedHandler(el: boolean): any {
this.loggedIn$.next(el);
}