My latest project involves creating a customized service. While the service function is returning data as expected, I encounter an issue when calling it in the controller - it returns 'undefined'.
Service:
var toDoListServices = angular.module('toDoListServices', []);
toDoListServices.factory('DataTasksService', function($http){
return {
getTasks: function(){
$http.get('js/data.json').success(function(data){
return data;
})
}
}
});
Controllers:
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'
]);