Reputation: 67
I just want to show one div if the user is logged in already or else I want to show another div with different content. Can anyone guide this to achieve this?
Upvotes: 0
Views: 927
Reputation: 1260
You'd use the authService.isUserLoggedIn()
method, that exposes an observable.
You could use it like this:
<div *ngIf="isLoggedIn;else #differentContent">
User is logged in
</div>
<ng-template #differentContent>
something else
</ng-template>
In your component controller you'd addd the isLoggedIn
property:
@Component({...})
export class MyComponent {
isLoggedIn: Observable<boolean> = this.authService.isUserLoggedIn();
constructor(private authService: AuthService) {}
}
Upvotes: 2