我注意到,我可以使用$ HTTP提供了这种方式:
Auth.login(userdetails).then(function(response){
//...
}
app.service('Auth', ['$http', function ($http) {
AuthService.login = function (credentials) {
return $http.
post('getauth.php', credentials).
then(function (res) {
//create the session, etc.
});
}]);
注意在HTTP前面的return语句,然后使用()上http而不是成功()。
为什么这样吗?有什么缺点吗?
可能重复[角HTTPPromise](http://stackoverflow.com/questions/16385278/angular-httppromise-difference -between-success-error-methods-and-thens-a) – Anubhav 2014-12-04 07:59:13
我刚刚回答了这个问题http://stackoverflow.com/questions/27287731/angular-http-service-success-error-then-methods/27288310#27288310 – Chandermani 2014-12-04 08:39:03