我正在嘗試使用$ resource進行ajax調用,並在從服務器接收數據時加載數據表。但是當我調用get()時,我得到$ promise爲未定義的。 我正在使用工廠撥打電話。 這裏是我廠:
app.factory('getAllUsers', [ '$resource', function($resource) {
return $resource('URL', {}, {get : {method : 'GET'}});
}]);
而且控制器:
app.controller('MyController',function($scope,$location,getAllUsers){
console.log("In controller");
getAllUsers.get().$promise.then(function(data) {
loadDatatable(data);
});
});
ERROR:getAllUsers.get()$承諾是不確定的
注:我在我的應用程序包括ngResource和index.html中的angular-resource.js也是如此。