AngularJS不是在释放模式工作(精缩) [英] AngularJS not working in release mode (minified)

查看:167
本文介绍了AngularJS不是在释放模式工作(精缩)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有AngularJS和角度指令用于引导一个项目,这两者已经通过的NuGet补充说。

I have AngularJS, and Angular directives for Bootstrap in a project, both of which have been added via Nuget.

编译调试=真正的后,一切工作正常,但一旦我改变的编译调试,角停止工作,并我碰到下面的错误在Chrome的控制台:

When compilation debug="true", everything works fine, but once I change compilation debug to false, Angular stops working, and I get the following error in Chrome's console:

Error: [$injector:unpr] http://errors.angularjs.org/1.2.15/$injector/unpr?p0=nProvider%20%3C-%20n
at Error (native)
at http://localhost:10366/bundles/angular?v=Bi8OwYOhmsGdeIKC46ZQQdIHX1faTIVR48lG9QG3GBw1:1:448
at http://localhost:10366/bundles/angular?v=Bi8OwYOhmsGdeIKC46ZQQdIHX1faTIVR48lG9QG3GBw1:1:14726
at Object.i [as get] (http://localhost:10366/bundles/angular?v=Bi8OwYOhmsGdeIKC46ZQQdIHX1faTIVR48lG9QG3GBw1:1:13802)
at http://localhost:10366/bundles/angular?v=Bi8OwYOhmsGdeIKC46ZQQdIHX1faTIVR48lG9QG3GBw1:1:14801
at i (http://localhost:10366/bundles/angular?v=Bi8OwYOhmsGdeIKC46ZQQdIHX1faTIVR48lG9QG3GBw1:1:13802)
at r (http://localhost:10366/bundles/angular?v=Bi8OwYOhmsGdeIKC46ZQQdIHX1faTIVR48lG9QG3GBw1:1:14014)
at Object.instantiate (http://localhost:10366/bundles/angular?v=Bi8OwYOhmsGdeIKC46ZQQdIHX1faTIVR48lG9QG3GBw1:1:14185)
at http://localhost:10366/bundles/angular?v=Bi8OwYOhmsGdeIKC46ZQQdIHX1faTIVR48lG9QG3GBw1:1:30669
at http://localhost:10366/bundles/angular?v=Bi8OwYOhmsGdeIKC46ZQQdIHX1faTIVR48lG9QG3GBw1:1:23558 angular?v=Bi8OwYOhmsGdeIKC46ZQQdIHX1faTIVR48lG9QG3GBw1:1
(anonymous function) angular?v=Bi8OwYOhmsGdeIKC46ZQQdIHX1faTIVR48lG9QG3GBw1:1

我的所有其他的JavaScript / CSS的正常工作。什么会导致角停止工作,一旦精缩?这是一个已知的问题?

All of my other Javascript/CSS works as expected. What could cause Angular to stop working once minified? Is this a known issue?

感谢

推荐答案

ASP.NET MVC的 JavaScript的文件时的编译调试值设置为。该角度教程包括有关缩小本说明:

ASP.NET MVC minifies javascript files when the compilation debug value is set to "false". The angular tutorial includes this note about minification:

由于角推断控制器的依赖从参数控制器的构造函数的名字,如果你要压缩JavaScript code为[你]控制器,它的所有函数参数会以及精缩,且依赖注入将不能正确识别的服务。

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 [your] controller, all of its function arguments would be minified as well, and the dependency injector would not be able to identify services correctly.

的最常用的技术来克服这个问题是内联括号符号,如:

The most common technique to overcome this problem is inline bracket notation, like:

phonecatApp.controller('PhoneListCtrl', ['$scope', '$http', function($scope, $http) {...}]);

这太问题解释微小安全语法的重要性: Angularjs缩小最佳实践

This SO question explains the importance of minification safe syntax: Angularjs minify best practice

这篇关于AngularJS不是在释放模式工作(精缩)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆