Angular JS Factory - undefined is not a problem

I am new to Angular JS. Here is my problem. I am trying to create a factory. But when I call factory, it gives me an error -Error undefined is not an object (evaluation: myService.getProjects)

the code:

myApp.factory('myService', function() { 
  return {
    getProjects: function() {
        return "Test";
    }
  };
});

myApp.controller('homeController',['$scope',function($scope,myService)
{
 $scope.projects=myService.getProjects();
 $scope.message="homeController";
}]);
+3
source share
1 answer

You forgot to enter your service. Try the following:

myApp.controller('homeController', ['$scope', 'myService', function($scope, myService) {
  $scope.projects = myService.getProjects();
  $scope.message = "homeController";
}]);
+4
source

All Articles