Reputation: 33
I am new to Angular JS. Here is my issue. I am trying to create a factory . But when I am calling factory it gives me an error -Error undefined is not an object (evaluating: myService.getProjects)
Code:
myApp.factory('myService', function() {
return {
getProjects: function() {
return "Test";
}
};
});
myApp.controller('homeController',['$scope',function($scope,myService)
{
$scope.projects=myService.getProjects();
$scope.message="homeController";
}]);
Upvotes: 3
Views: 3287
Reputation: 3366
You forgot to inject your service. Try this:
myApp.controller('homeController', ['$scope', 'myService', function($scope, myService) {
$scope.projects = myService.getProjects();
$scope.message = "homeController";
}]);
Upvotes: 4