I have the following code:
appModule = angular.module(\'appModule\', []);
appModule.factory(\'sharedApplication\', function($rootScope, $http) {
var sharedApp
ng-annotate is also a good library so that the required dependency is injected automatically. You should check it out.
Code sample:
/* ngInject */
appModule.factory('sharedApplication', function($rootScope, $http) {
var sharedApp;
sharedApp = {};
sharedApp.currentView = "home-section";
sharedApp.pastEvents = null;
$http.get('api/highlights').success(function(response) {
return sharedApp.pastEvents = response.data;
});
return sharedApp;
});
Then you don't have to write:
appModule.factory('sharedApplication', ['$rootScope','$http',
function($rootScope, $http) {
var sharedApp;
sharedApp = {};
sharedApp.currentView = "home-section";
sharedApp.pastEvents = null;
$http.get('api/highlights').success(function(response) {
return sharedApp.pastEvents = response.data;
});
return sharedApp;
}]);
Try
appModule.factory('sharedApplication', ['$rootScope','$http',function($rootScope, $http) {
}]);
regards
The more elegant and easier to read approach:
appModule.factory('myFactory', myFactory);
myFactory.$inject = ['$rootScope','$http'];
function myFactory($rootScope, $http) {
...
}