【发布时间】:2016-02-09 09:41:44
【问题描述】:
以下两个 sn-ps 嵌入在用于登录用户的角度控制器中(取自 angular-meteor tutorial):
this.login = function() {
Meteor.loginWithPassword(this.credentials.email, this.credentials.password, (err) => {
if (err) {
this.error = err.reason;
}
else {
$state.go('index');
}
});
};
和:
this.login = function() {
Meteor.loginWithPassword(this.credentials.email, this.credentials.password, function(err) {
if (err) {
this.error = err.reason;
}
else {
$state.go('index');
}
});
};
第一个导致 AngularJS 在回调后更新 error 的值,但第二个 sn-p 不会触发更新。唯一的区别是在第一个中使用了速记方法声明。这是什么原因?
【问题讨论】:
-
请问脚本你是如何调用这个函数的?
标签: javascript angularjs meteor methods shorthand