使用严格注释模式查找缩小错误-$ injector:unpr未知提供程序 [英] Use Strict Annotation Mode to Find Minification Bugs -- $injector:unpr Unknown provider
问题描述
我有一个正在运行的Angular 7/AngularJS混合应用程序.使用"npm start",一切都在开发模式下运行良好.但是,在构建生产版本之后,页面会给我一个
I have an Angular 7/AngularJS hybrid app that I'm running. Everything runs fine in development mode using "npm start". However, after building a production version, the page gives me a
错误.我试过只运行Angular 7代码,并且效果很好.我已经尝试调试,并且app.js
文件中的angularjs代码正在正常执行.该代码似乎来自我的app.module.ts错误
error. I've tried only running the Angular 7 code and that works fine. I've tried debugging and my angularjs code in an app.js
file is being executed fine. The error seems to be coming from my app.module.ts when the code
this.upgrade.bootstrap(document.documentElement, ['app'], { strictDi: false })"
被执行.
export class AppModule {
constructor(private upgrade: UpgradeModule) { }
ngDoBootstrap() {
this.upgrade.bootstrap(document.documentElement, ['app'], { strictDi: false });
}
}
declare var angular: any;
angular
.module("app")
.directive("example", downgradeComponent({ component: ExampleComponent }) as angular.IDirectiveFactory);
不确定为什么只在生产模式下出现此错误.我已经将该应用程序部署为IIS中的应用程序.任何帮助,将不胜感激.谢谢.
Not sure why I only get this error in production mode. I've deployed the app as an application in IIS. Any help would be appreciated. Thanks.
推荐答案
使用严格注释模式查找缩小错误
angular.bootstrap(element, ['app'], { strictDi: false })
从文档中:
strictDi
-禁用应用程序的自动功能注释.这是为了协助查找破坏最小代码的错误.默认值为false
.
strictDi
- disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. Defaults tofalse
.
- AngularJS angular.bootstrap API参考 >
如何从HTML启用严格注释模式
<body ng-app="app" ng-strict-di="true">
<!-- ... -->
</body>
从文档中:
ngStrictDi
(可选)布尔值
如果该属性存在于app元素上,则将以"strict-di"模式创建注射器.这意味着应用程序将无法调用不使用显式函数注释(因此不适合缩小)的函数,如和有用的调试信息将有助于跟踪这些错误的根源.
ngStrictDi
(optional) boolean
if this attribute is present on the app element, the injector will be created in "strict-di" mode. This means that the application will fail to invoke functions which do not use explicit function annotation (and are thus unsuitable for minification), as described in the Dependency Injection guide, and useful debugging info will assist in tracking down the root of these bugs.
有关其他信息,请参见
这篇关于使用严格注释模式查找缩小错误-$ injector:unpr未知提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!