由于某些原因,我的boolean
似乎没有设置为true
,它在我之前的代码中有效。两个代码基本相同,因此*ngIf
语句在满足if()
语句后应该变为true,setTimeout
工作正常。
<i class="fa fa-spinner fa-spin" *ngIf="isLoading"></i>
当前:
isLoading: boolean;
login(user){
var authenticatedUser = users.find(u => u.username === user.username);
var sessionKey = btoa(user.username);
if(authenticatedUser && authenticatedUser.password == user.password) {
this.isLoading = true;
localStorage.setItem('sessionKey', sessionKey);
setTimeout(() => {
this._router.navigate(['/dashboard']);
}, 1000);
return true;
}
return false;
}
一个:
isLoading: boolean;
loginAction (){
var uname = this.data.username;
var pass = this.data.password;
// dummy session key
var sessionKey = (btoa(uname) + btoa(pass));
if(uname=="user1" && pass=="pass1"){
this.isLoading = true;
localStorage.setItem('sessionKey', sessionKey);
setTimeout(() => {
this._router.navigate(['/dashboard']);
}, 1000)
}...