I have an angular 2 app generated by ng cli.
– When I run ng build (or) ng build –prod –aot=false and serve up the page things just work fine.
– But when I try to enable aot by running ng serve –aot=true and serve up,the page breaks with multiple DI errors like belowVery hard to debug. Any idea on how to debug these issues?
例外:没有选项提供商!
error_handler.js:59 ORIGINAL STACKTRACE:
ErrorHandler.handleError @ error_handler.js:59
(匿名)@ application_ref.js:272
webpackJsonp.679.ZoneDelegate.invoke @ zone.js:229
onInvoke @ ng_zone.js:271
webpackJsonp.679.ZoneDelegate.invoke @ zone.js:228
webpackJsonp.679.Zone.run @ zone.js:113
(匿名)@ zone.js:509
webpackJsonp.679.ZoneDelegate.invokeTask @ zone.js:262
onInvokeTask @ ng_zone.js:262
webpackJsonp.679.ZoneDelegate.invokeTask @ zone.js:261
webpackJsonp.679.Zone.runTask @ zone.js:151
drainMicroTaskQueue @ zone.js:405
例如:在您的AppModule中必须执行以下操作:
import {Logger,Options} from "angular2-logger/core";
然后在您的提供商列表中确保添加选项:
providers: [ Logger,Options // <-- this is key ]
这使得确定的AOT包括“选项”.
现在,我是怎么发现的?该错误为您提供了无法找到“选项”的提示.所以我使用Developer Tools来查看使用sourceMaps生成的源代码(我查看了main.bundle.js).在那里我搜索了字符串“选项”,唯一的命中也给了我最后的提示:
__WEBPACK_IMPORTED_MODULE_9_angular2_logger_core__["Options"])
现在,在查看了我必须提供选项的文档后,我才意识到这一点.
希望这可以帮助. 原文链接:https://www.f2er.com/angularjs/140932.html