Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Your factory has to return something. It's the return value that's injected:
myApp.factory('myDataService', ['$http', function($http){ var myDataService = {}; myDataService.getData = function() { ... }) return myDataService; };
More on Angular factoriesAngular factories
More on Angular factories
myApp.factory('myDataService', ['$http', function($http){ var myDataService = {}; myDataService.getData = function() { $http.get('/api/reviews') .success(function(data, status, headers, config) { console.log("Data received"); return data; }) .error(function(data, status, headers, config) { console.error("No data received"); }) return myDataService; };