简体   繁体   English

使用min.js文件的angular.module配置

[英]angular.module config using min.js files

I want to configure my angular module like this: 我想像这样配置我的角度模块:

var app = angular.module('myModule', []).config(function ($sceDelegateProvider) {
   $sceDelegateProvider.resourceUrlWhitelist([
      ...
   ]);
});

But when I minify the js file the $sceDelegateProvider parameter is being convert to shorter name. 但是,当我缩小js文件时, $sceDelegateProvider参数将被转换为较短的名称。

I didnt find a way to pass the parameter name as a string. 我没有找到将参数名称作为字符串传递的方法。 (like it is in the module constructor) (就像在模块构造函数中一样)

Thanks. 谢谢。

Instead of passing a function into config, pass an array where the first variables are the parameter names as string and the last one is the function: 而不是将函数传递到config中,而是传递一个数组,其中第一个变量是参数名称(字符串形式),最后一个是函数:

var app = angular.module('myModule', []).config(['$sceDelegateProvider' , function ($sceDelegateProvider) {
   $sceDelegateProvider.resourceUrlWhitelist([
      ...
   ]);
}]);

You can add $sceDelegateProvider as a dependency in your config: 您可以在配置中添加$sceDelegateProvider作为依赖项:

<your-module>.config(['$sceDelegateProvider', function($sceDelegateProvider){}]);

Then angular will inject $sceDelegateProvider to your config function mapping it to the parameter regardless of the parameter name. 然后,angular会将$sceDelegateProvider注入到您的配置函数中,而不考虑参数名称,将其映射到参数。

Try 尝试

angular.module('myModule', []) 
    .config(['depProvider', function(depProvider) { 
        // ...     
      }])

See here for more details 看到这里更多细节

https://docs.angularjs.org/guide/di https://docs.angularjs.org/guide/di

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM