Issue
I'm building an Angular 7 app and using BehaviorSubject to keep the user authentication state as it's recommended on every source on the internet.
Since BehaviorSubject is an Observable, why can't I fire the onComplete() method?
Here's the code (which seems pretty classic to me):
this.authService.authenticationState.subscribe(state => {
this.isLoggedIn = state;
},
err => console.log(err),
() => console.log('complete')
);
authService
authenticationState = new BehaviorSubject(false);
'complete' is not logged. Is there something I'm doing wrong?
SOLUTION
this.authService.authenticationState.subscribe(state => {
this.isLoggedIn = state;
this.authService.authenticationState.complete();
},
err => console.log(err),
() => console.log('complete')
);
then the complete() method is fired
Solution
I think you can trigger complete like this when you are ready for the complete section of the subscription to be called.
authenticationState.complete();
Answered By - Dince12
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.