使用严格注释模式查找缩小错误-$ injector:unpr未知提供程序 [英] Use Strict Annotation Mode to Find Minification Bugs -- $injector:unpr Unknown provider

查看:158
本文介绍了使用严格注释模式查找缩小错误-$ injector:unpr未知提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行的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

[$ injector:unpr]未知提供者:e

错误.我试过只运行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 to false.

- AngularJS angular.bootstrap API参考


如何从HTML启用严格注释模式

<body ng-app="app" ng-strict-di="true">
   <!-- ... -->
</body>

从文档中:

  • 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.

- AngularJS ng-app指令API参考

有关其他信息,请参见

这篇关于使用严格注释模式查找缩小错误-$ injector:unpr未知提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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