I have the following BehaviorSubject in a service:
isAuthenticated = new BehaviorSubject<boolean>(false);
And I am using it as follows in a component:
authenticated: Observable<boolean>;
constructor(private accountService: AccountService) { }
ngOnInit() {
this.authenticated = this.accountService.isAuthenticated.asObservable();
}
And in the template I do something like :
<li class="login-button" *ngIf="!authenticated | async">
<a (click)="authenticate()">Log in</a>
</li>
<li *ngIf="authenticated | async">
<a>Logged in</a>
</li>
The issue is that I dont see any of the two li
, although the assumption is that the first one should appear since I am assigning the initial value of the Subject to false.
What am I doing wrong?
next
method of theBehaviourSubject
– Scorpio!(authenticated | async)
to make sure it's using theasync
pipe on the Observable and not the result of!authenticated
– Laurentianext
for BehaviourSubject ! – Ratiocination