Meteor.setTimeout() inside in Meteor.loginWithPassword()


#1

Hello, I need help.
My code is in a login.
When the user click in login: I put a button disable to avoid that the user do click many times when the system is working, waiting for a answer

My code works fine, but I put a loader class when the user click in button login.

When the user put the password and is acepted, the system send us to the next view. This works fine, but…
The problem is:
When the user put a invalid pasword this.loadingActive = true; dont change… the button remain with the spin active forever. I mean something happend that the variable loadingActive dont change to true

my html

<button class="btn btn-default btn-lg btn-block"
        ng-class="{'disabled': login.loadingActive === false}"
        ng-disabled="loginForm.$invalid || login.loadingActive === false"
        ng-click="login.login()">
    <span ng-hide="login.loadingActive" class="fa fa-refresh animacion-cargando"></span>
    <span ng-hide="login.loadingActive">loading...</span>
    <span ng-show="login.loadingActive">Login</span>
</button>

This is my js file


login() {
    this.loadingActive = false;
    this.error = '';
    Meteor.loginWithPassword(this.credentials.email.toLowerCase(), this.credentials.password,
        this.$bindToContext((err) => {
            Meteor.setTimeout(() => {
                if (err) {
                    this.loadingActive = true;
                    this.error = err;
                } else {
                    this.loadingActive = true;
                    this.$state.go('app.pageOne');
                }
            }, 1000);
        })
    );
}

Why when I put a Meteor.setTimeout inside a Meteor.loginWithPassword happen this?
any ideas?