how to inject dependency into module.config(configFn) in angular

后端 未结 8 1116
轮回少年
轮回少年 2020-11-27 14:40

In Angular, we can inject $routeProvider to the config function

module.config(function ($routeProvider) {


});

I

8条回答
  •  清酒与你
    2020-11-27 15:17

    You can do it like this:

    (function() {
        'use strict';
    
        angular.module('name', name).config(config);
        // You can do this:
        config.$inject = ['$routeProvider', 'myService'];
    
        function config($routeProvider, myService) {
            // Or better to use this, but you need to use ng-annotate:
            /* ngInject */
    
        }
    });
    

    It is best practice that is described here

提交回复
热议问题