What is the best way to inject a service into my router so that its JSON result will be accessible throughout the entire application?
Router:
export default ['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider, MainController, ConfigService) {
$stateProvider.state('home', {
url: '/',
controller: 'MainController',
resolve: {
/* @ngInject */
someResolve: (ConfigService) =>
ConfigService.config()
}
});
$urlRouterProvider.otherwise('/');
}];
Service:
export default function ConfigService() {
return ['$http', function($http) {
this.config = function() {
return $http({
url: '../json/config.json',
method: 'GET'
}).then(function(result) {
console.log(result);
});
};
}];
}
Maincontroller
export default function MainController () {
return ['$scope','$location','ConfigService','$window', function($scope, $location, ConfigService, $window) {
ConfigService.config();
}];
}