How to inject a service into app.config in AngularJS

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

$routeProvider
    .when(\'/hje         


        
3条回答
  •  轮回少年
    2020-12-08 17:56

    1. angular.config only accepts Providers
    2. every service, factory etc are instances of Provider

    So to inject a service in config you just need to call the Provider of the service by adding 'Provider' to it's name.

    angular.module('myApp')
      .service('FooService', function(){
        //...etc
      })
      .config(function(FooServiceProvider){
        //...etc
      });
    

提交回复
热议问题