【发布时间】:2013-04-02 08:48:00
【问题描述】:
看来我的要求:
angular.module('todoApp').factory('UsersService', ['$resource', 'paramsService', '$q', function($resource, paramsService, $q){
var server = paramsService.serverUrl;
return {
'auth': function(username, password){
var $response = {};
$resource(server + '/api/account/auth', {}, {call: {method: 'POST', headers: {'Content-Type': 'application/json'}}}).call(
{'username': username, 'password': password},
function(data){
console.log(data);
$response = data;
}
);
console.log($response);
return $response;
},
}
}]);
在成功函数中,我有数据响应,但变量 $response 为空。我知道但为什么会发生,但找不到等待响应返回它的方法。如何从 $resource 获得响应?
【问题讨论】:
-
查看 docs.angularjs 网站上的教程中的示例。范围项目接受承诺
标签: angularjs