【发布时间】:2016-04-22 00:12:01
【问题描述】:
我正在阅读一些关于 angular.js 的教程并遇到了这个表达式:
.then(handleRequest, handleRequest)
我想知道将 2 个相同的函数传递给 .then() 是什么意思?
这里有更多上下文:
function MainCtrl(user, auth) {
var self = this;
function handleRequest(res) {
var token = res.data ? res.data.token : null;
if(token) { console.log('JWT:', token); }
self.message = res.data.message;
}
self.login = function() {
user.login(self.username, self.password)
.then(handleRequest, handleRequest)
}
...
}
angular.module('app', [])
.controller('Main', MainCtrl)
....
})();
原始教程可以在这里找到:https://thinkster.io/angularjs-jwt-auth
【问题讨论】:
-
看看over here。在这种情况下,它看起来像是试图获取实际应该使用的
.finally(handleRequest)的行为。
标签: javascript angularjs angular-promise