我試圖讓使用$resource
請求的響應得到響應的值,例如我有:
angular.module('app').factory('AuthResource', ['$resource', function($resource) {
return {
isAuthenticated : function() {
return $resource('/api/v1/auth/authenticated').query();
}
}
}]);
然後在我的控制,我調用這個服務,做:
console.log(AuthResource.isAuthenticated());
這不會返回實際結果,它只是單個對象{'success' : 'true'}
。
相反,它返回:
Resource {$resolved: false, $then: function, $get: function, $save: function, $query: function…}
$resolved: true
$then: function (callback, errback) {
success: false
__proto__: Resource
我如何去獲得實際返回的對象?我沒有將這個應用到任何模型,只是使用數據來確定一些路由。
謝謝!
退房[這個答案] [1],它幫了我 [1]:http://stackoverflow.com/a/16197255/1505895 – paynestrike 2013-06-28 01:34:57