私はService
とを持っていController
ます。コントローラは で関数を呼び出しgetItems()
ますService
。はデータのをService
返しますarray
。
ただし、奇妙なことに、コントローラーはこれを受信していないようです。
コントローラ:
ItemModule.controller('ItemController', ['$scope', 'ItemService',
function ($scope, ItemService) {
$scope.items = [];
$scope.getItems = function() {
$scope.items = ItemService.getItems();
}
$scope.getItems();
}
]);
サービス:
ItemModule.service('ItemService', ['$rootScope', '$http',
function($rootScope, $http) {
this.getItems = function() {
$http.get($rootScope.root + '/products').success(function(data) {
// This prints it out fine to the console
console.log(data);
return data;
});
}
}
]);
私は何を間違っていますか?