【发布时间】:2015-07-09 20:57:03
【问题描述】:
我确定我在这里缺少一些简单的东西,但我无法让它工作.. 我想使用工厂,以便我可以在多个控制器中重用数据。
(function() {
'use strict';
angular
.module('www')
.factory('profileFactory', profileFactory);
profileFactory.$inject = ['Restangular'];
/* @ngInject */
function profileFactory(Restangular) {
var service = {
getUserData: Restangular.one('/user/profile/').getList(),
getFriendList: Restangular.all('api/users/getfriendsinvitations/').getList()
};
return service;
}
})();
控制器:
(function() {
'use strict';
angular
.module('www')
.controller('ProfileController', ProfileController);
ProfileController.$inject = ['profileFactory'];
/* @ngInject */
function ProfileController() {
activate();
function activate(profileFactory, $scope) {
profileFactory.getFriendList.then(function (homeFriends) {
$scope.homeFriends = homeFriends;
});
}
}
})();
而且我不断收到“TypeError: Cannot read property 'getFriendList' of undefined”
编辑:我也试过了,https://github.com/mgonto/restangular#decoupled-restangular-service,但没有运气!
【问题讨论】:
-
请在标题中形成一个实际问题。它看起来像标签。另外,请扩展您为自己解决此问题所做的努力。您是否检查过第一/第三方库的文档?
-
你能提供一个plunker文件吗?我们需要知道其他细节,例如:“您调用服务的方式”等。
标签: angularjs factory restangular angular-promise angularjs-factory