我试图了解我真正在做什么,因为我觉得我缺乏一些东西。您能否指出我的某个地方或确认我的错误/理解?
request.then(function(response) {
updateCurrentUser(response.data.data);
currentUser.isAuthenticated();
});
基本上是这样吗?
request = {
then : function (foo){
foo("first")
} }
request.then(function (response) { console.log(response) ; });
指示:
AuthenticationService.login($scope.user.email, $scope.user.password).then(function(loggedIn) {
if ( !loggedIn ) {
$scope.authError = "Login failed. Please check your credentials and try again.";
}
});
AuthenticationService 作为工厂:
login: function(email, password) {
var request = $http.post('http://', {email: email, password: password});
return request.then(function(response) {
updateCurrentUser(response.data.data);
return currentUser.isAuthenticated();
});
},
我不明白的是,loggedIn 变量的值为什么等于语句返回 currentUser.isAuthenticated();的值。返回AND 不等于原始的 then(function(response),因为我从 AuthenticationService 返回承诺。关于上面的示例,如何实现这一点?
谢谢你。