*ngIf not working as expected with observable *ngIf not working as expected with observable angular angular

*ngIf not working as expected with observable


Put the async pipe in parenthesis.

<a class="router-link nav-item" routerLink="/login" *ngIf="!(isLoggedIn$ | async)">  Login</a><a class="router-link nav-item" (click)="onLogout()" *ngIf="isLoggedIn$ | async">  Logout</a>


You can also refactor to use the else part of ngIf directive:

<a class="router-link nav-item" (click)="onLogout()" *ngIf="isLoggedIn$ | async; else loginBlock">    Logout</a><ng-template #loginBlock>    <a class="router-link nav-item" routerLink="/login">        Login    </a></ng-template>

You can see more examples in the docs.