I would like to show the something only if the user is logged in. The user is an observable
and to show/hide I would like to use NgIf
.
But the NgIf hides the content forever, even I see could verify the user changed from null
to an object
userObserver: Observer<any>;
user: Observable<any>;
constructor() {
this.user = new Observable((observer: Observer<string>) => {
this.userObserver = observer;
});
this.user.subscribe((x) => {
console.log('next', x);
});
}
public login(credentials: ICredentials): Observable<any> {
this.userObserver.next(credentials);
return this.user;
}
In the template I use the observable like:
{{user | async | json}} // will change
<div *ngIf="user | async">user here</div> // will never show up
Edit I got it working using:
isLoginSubject = new BehaviorSubject<any>(null);
user: Observable<any> = this.isLoginSubject.asObservable();
But then we can change the question to why? what difference makes it out?