【发布时间】:2017-01-18 20:37:59
【问题描述】:
我的应用程序中有身份验证提供程序 - AuthHelperProvider。当用户尝试登录失败时,应禁用登录按钮。为此,我在提供程序中发布事件并订阅 LoginPage 组件:
AuthHelperProvider
this.http.get(query).map(res => <{error: string, clientId: string}>res.json()).subscribe(response => {
if (response.error == '') {
console.log(this.TAG + 'log in without errors');
if (keepSingIn) {
this.storage.set(this.KEEP_LOGGED_IN, true);
this.setUsername(login);
this.setPassword(password);
}
this.setClientId(response.clientId);
this.events.publish('user:login');
this.attemptCount = 0;
/*this.navCtrl.setRoot(TabsPage);*/
} else {
console.log(this.TAG + 'log in with errors' + response.error);
this.events.publish('user:failedAttempt',++this.attemptCount);
this.errorHelper.showErrorAlert(response.error);
}
});
登录页面
this.events.subscribe('user:failedAttempt', (attemptsCount) => {
console.log(this.TAG + 'number of failed attempts: ' + attemptsCount);
if (attemptsCount >= 3) {
this.isLoginBlocked = true;
this.errorAlert.showErrorToast('Number of attempts exceeded, try to restore your account');
} else {
this.isLoginBlocked = false;
}
});
但我遇到了意想不到的行为:订阅事件的处理程序称为 attemptsCount 次。看起来很傻,但我做错了什么?
【问题讨论】:
-
您好,我刚刚删除了我的错误答案,您可能应该将您的发现添加到答案中并在几天后接受它,这样该线程就完成了问答。
标签: angular ionic-framework ionic2