我敢肯定這件事情簡單,我在這裏失蹤,但我不能得到這個工作.. 我想用一個工廠,這樣我可以重複使用多個控制器的數據。不能得到restangular工廠上班
(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;
});
}
}
})();
而且我不斷收到 「類型錯誤:無法讀取的未定義的屬性 'getFriendList'」
編輯:我曾嘗試爲好,https://github.com/mgonto/restangular#decoupled-restangular-service,但沒有運氣!
請形成你的標題一個實際的問題。它看起來像標籤。另外,請擴展您自己解決這個問題的努力。你檢查過第一/第三方圖書館的文件嗎? – onebree
你能提供一個plunker文件嗎?我們需要知道另一個細節,例如:「您撥打服務的方式」等。 –