My class has a variable:
userPermission: any;
and I assign this variable during login
login(model: any): Observable<any> {
return this.http.post(this.baseUrl + 'login', model)
.pipe(map((response: any) => {
const user = response;
this.userPermission = response.permission;
}));
}
I used this variable as condition in view:
<li *ngIf="isAdmin()" class="nav-item">
and
isAdmin(): boolean {
if (this.userPermission === EPermission.ADMIN) {
return true;
} else {
return false;
}
}
And it works but only 1 time, If I debug it, the variable has a permission "ADMIN" but when i clicked on my website on item
<li *ngIf="isAdmin()" class="nav-item"> - (this item has no action)or on others item on my website -
the variable is going to undefined despite my user is still admin.
Why the value is going from true/false to undefined ? My variable userPermission is assigned only in one place during login and this method is called only one time. So how it is possible. It seems like the variable is resetting itself.