How to inject a service into app.config in AngularJS

前端 未结 3 1053
后悔当初
后悔当初 2020-12-08 17:19
wikiApp.config([\'$routeProvider\',\'authService\', 
  function($routeProvider,authService) {
var admin = authService.getLoggedin();

$routeProvider
    .when(\'/hje         


        
3条回答
  •  既然无缘
    2020-12-08 18:08

    During the configuration phase you can only ask for providers ($routeProvider, $locationProvider etc.) it means you cannot inject any other instance, so I would suggest injecting your service in the run phase, there your will have an instance of your service.

    // configuration
    app.config(function($routeProvider) {
    
    });
    
    //inject any instance 
     app.run(function($rootScope,authService) {
      var admin = authService.getLoggedin();
    
      $rootScope.$on('$routeChangeStart', function(next, current) { 
         // your logic here...
      }); 
    });
    

提交回复
热议问题