isLogin
如果 Ionic Storage = ,如何显示按钮true
。
import { Storage } from '@ionic/storage';
constructor(
private storage: Storage,
) { }
login(phone: string, password: string) {
return this.http.post<any>(`/api/user/login`, { phone, password })
.pipe(map(user => {
this.storage.set('currentUser', user);
this.storage.set('isLogin', true);
this.currentUserSubject.next(user);
return user;
}));
}
ngOnInit() {
this.storage.get('isLogin').then(result => {
this.isLoginVal = result
console.log(this.isLoginVal)
})
}
<button mat-icon-button (click)="goToLogin()" *ngIf="!isLoginVal; else logged">
<mat-icon>menu</mat-icon>
</button>
<ng-template #logged>
<button mat-icon-button (click)="drawer()">
<mat-icon>user</mat-icon>
</button>
</ng-template>