我有以下控制器使用ember.js
和ember-auth
gem。该控制器有效,但loginError
每次我登录时都会设置属性。
BaseApp.SignInController = Auth.SignInController.extend({
email: null,
password: null,
loginError: false,
signIn: function() {
this.registerRedirect();
Auth.signIn({
email: this.get('email'),
password: this.get('password')
});
this.set('loginError', true); // Sets correctly but each time
Auth.on('signInError', function() {
console.log("This is a signin error");
});
}
});
显然我想做的是设置loginError
在true
这样调用的函数内部Auth.on
:
BaseApp.SignInController = Auth.SignInController.extend({
email: null,
password: null,
loginError: false,
signIn: function() {
this.registerRedirect();
Auth.signIn({
email: this.get('email'),
password: this.get('password')
});
Auth.on('signInError', function() {
this.set('loginError', true); // Doesn't set the controller's property
console.log("This is a signin error");
});
}
});
但这显然不起作用,因为回调内部的范围不同。也许我错过了一些非常基本的东西。我怎样才能让它工作?