0
我創建一個自定義服務,它在哪裏工作,正在返回給我的函數服務的數據,問題是當我在控制器中調用它時,它返回我'undefined'。定製服務返回undefined
服務:
var toDoListServices = angular.module('toDoListServices', []);
toDoListServices.factory('DataTasksService', function($http){
return {
getTasks: function(){
$http.get('js/data.json').success(function(data){
return data;
})
}
}
});
控制器:
var toDoListController = angular.module('toDoListController', []);
toDoListController.controller('ListController', ['$scope', 'DataTasksService', function($scope, DataTasksService){
$scope.tasks = DataTasksService.getTasks();
}]);
App.js:
var myApp = angular.module('myApp', [
'ngRoute',
'toDoListController',
'toDoListServices'
]);