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;
}]);