In my SchoolyearController the parameter schoolyears is undefined.
How can I retrieve my schoolyears objects in the schoolyearService and inject the result into the SchoolyearController?
SERVICE
'use strict';
angular.module('schoolyear').service('schoolyearService', function ($http) {
return {
getSchoolyears: function () {
var path = 'scripts/model/schoolyears.json';
$http.get(path).then(function (response) {
return response.data.schoolyears; // The schoolyears here are the 6 expected JS objects in an array, so far so good but how do I get those objects into the SchoolyearController as parameter ?
});
}
};
});
UI-ROUTER
resolve: {
schoolyearService: ['schoolyearService',
function (schoolyearService) {
return schoolyearService.getSchoolyears();
}]
},
CONTROLLER
'use strict';
angular.module('schoolyear').controller('SchoolyearController', function ($scope, schoolyears) {
$scope.schoolyears = schoolyears; // I do not want to do a $http request here I just want to get passed the data here !!!
});
UPDATE
Still the schoolyears in the resolved property are undefined, why?
FACTORY
'use strict';
angular.module('schoolyearModule').factory('schoolyearFactory', function ($http) {
return {
getSchoolyears: function () {
var path = 'scripts/model/schoolyears.json';
$http.get(path).then(function (response) {
return response.data.schoolyears; // The schoolyears here are the 6 expected JS objects in an array
});
}
};
});
UI-ROUTER
resolve: {
schoolyears: function(schoolyearFactory) {
var schoolyears = schoolyearFactory.getSchoolyears();
return schoolyears;
}
},
CONTROLLER
'use strict';
angular.module('schoolyearModule').controller('ProjectsController', function ($scope, schoolyears) {
$scope.schoolyears = schoolyears; // I do not want to do a $http request here I just want to get passed the data here !!!
});