我的项目中有 AngularJS 和 Bootstrap 的 Angular 指令,这两个指令都是通过 Nuget 添加的。
When 编译调试=“真”,一切都很好,但是一旦我改变了编译调试 to false,Angular 停止工作,并且我在 Chrome 控制台中收到以下错误:
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 都按预期工作。什么可能导致 Angular 一旦缩小就停止工作?这是一个已知的问题?
Thanks
ASP.NET MVC缩小 JavaScript http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification文件时compilation debug
值设置为"false"
. The 角度教程 http://docs.angularjs.org/tutorial/step_05包括有关缩小的注释:
由于 Angular 从控制器的构造函数的参数名称推断控制器的依赖关系,因此如果您要缩小[您的]控制器的 JavaScript 代码,则其所有函数参数也将被缩小,并且依赖项注入器将无法正确识别服务。
解决此问题的最常见技术是内联括号表示法,例如:
phonecatApp.controller('PhoneListCtrl', ['$scope', '$http', function($scope, $http) {...}]);
这个SO问题解释了缩小安全语法的重要性:Angularjs 缩小最佳实践 https://stackoverflow.com/questions/18782324/angularjs-minify-best-practice
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)