I am just learning how to use services to slim down my controllers.
I created a plunker and I am returning this error: Error -- TypeError: undefined is not a function pointing to this line ".then(function(crops){"
Here is my index.html (pretty simple)
<body ng-controller="MainController">
<pre>{{selectedCrops | json}}</pre>
</body>
and here is script.js
(function(){
angular.module('app',[]);
angular.module('app')
.service('LoanSvc', function($http, $q){
this.getSelectedCrops = function(){
return {
show_corn: true,
show_beans: true,
show_sorghum: true,
show_wheat: true,
show_cotton: true,
show_rice: true,
show_peanuts: true,
show_sugarcane: true
};
}
});
angular.module('app').controller('MainController', function($scope, LoanSvc){
LoanSvc.getSelectedCrops()
.then(function(crops){
$scope.selectedCrops = crops;
})
});
}());
Any guidance is coveted!
Thanks in advance.