【发布时间】:2014-06-09 10:15:57
【问题描述】:
我正在为应用程序和内部服务使用https://github.com/StarterSquad/startersquad.github.com/tree/master/examples/angularjs-requirejs-2 文件夹结构,并且我有以下代码:
define(['./module'], function(services) {
'use strict';
services.factory('user_resources', ['$resource', '$location', function($resource, $location) {
return $resource("", {},
{
'getAll': {method: "GET", url:'JSON/myList.JSON',isArray:true}
});
}]);
});
在控制器中我有以下代码:
define(['./module'], function (controllers) {
'use strict';
controllers.controller('myListCtrl',['Phone','Phone1','loginForm','$scope','$http','user_resources','CreditCard',function(Phone,Phone1,loginForm,$scope,$http,user_resources,CreditCard){
console.log(user_resources.getAll())
}]);
});
返回 [$promise: Object, $resolved: false] 如何从中获取数据?
我做了同样的事情 this tutorial,但在我的情况下它返回承诺,在教程中它直接返回数据
【问题讨论】:
-
它返回一个承诺 -
user_resources.getAll().then(function(data) { //here is your data}) -
我已经尝试过了,但是错误提示 TypeError: undefined is not a function at new
myListCtrl.js
标签: angularjs promise angular-services