angular2 obj:布尔值不起作用

时间:2016-07-08 08:54:13

标签: javascript angularjs angular

由于某些原因,我的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)
        }...

0 个答案:

没有答案