角度控制工作不精缩后,JS文件?角度、文件、工作、不精缩后

2023-09-14 00:12:43 作者:史努比@

我是新来AngularJS。我已创建使用AngularJS在VS2012新的应用程序。我有微小适用于我的JavaScript文件,但缩小后,不是为我工作的结合。因为在 $范围关键字的角度理解就是转化为

I am new to AngularJS. I have create a new application in VS2012 using AngularJS. I have apply minification to my JavaScript file, but after minification the binding in not working for me. because the $scope keyword that angular understand is convert to a.

请让我知道如何应用到微小文件angularJS?

Please let me know how to apply minification to angularJS file ?

推荐答案

从http://docs.angularjs.org/tutorial/step_05:

由于角从参数控制器的构造函数的名称来推断控制器的依赖关系,如果你要压缩JavaScript code代表PhoneListCtrl控制器,它的所有函数参数将被缩小的同时,和依赖注入将无法正确地识别服务

Since angular infers the controller's dependencies from the names of arguments to the controller's constructor function, if you were to minify the JavaScript code for PhoneListCtrl controller, all of its function arguments would be minified as well, and the dependency injector would not be able to identify services correctly.

要克服因微小的问题,只是分配与服务标识符的字符串数组到$注入控制器功能的属性,就像在片段(注释掉)的最后一行提示:

To overcome issues caused by minification, just assign an array with service identifier strings into the $inject property of the controller function, just like the last line in the snippet (commented out) suggests:

PhoneListCtrl $注射='$范围,$ HTTP'];

还有指定这种依赖关系列表,并避免微小问题的另一种方式 - 使用后跟函数的括号标记它包装的功能被注入到字符串数组(重新presenting依赖名称)被注入:

There is also one more way to specify this dependency list and avoid minification issues — using the bracket notation which wraps the function to be injected into an array of strings (representing the dependency names) followed by the function to be injected:

VAR PhoneListCtrl = ['$范围,$ HTTP',函数($范围,$ HTTP){/ *构造函数体* /}];

这两种方法都用,可以通过角注入任何功能工作,所以就看你的项目的风格指南来决定你使用哪一个。

Both of these methods work with any function that can be injected by Angular, so it's up to your project's style guide to decide which one you use.