【发布时间】:2020-04-04 04:09:40
【问题描述】:
错误说明 我正在使用 Angular 的新 IVY 编译器,以及新的延迟加载功能(这里的 ivy 延迟加载教程:https://www.debugbear.com/blog/lazy-loading-angular-components-without-a-router)
当延迟加载模块并将组件的实例添加到我的应用程序时,ng-select 不会出现在组件中,并且我在控制台中收到此错误:
core.js:6354 ERROR NullInjectorError: R3InjectorError(AppModule)[InjectionToken ng-select-selection-model -> InjectionToken ng-select-selection-model -> InjectionToken ng-select-selection-model]:
NullInjectorError: No provider for InjectionToken ng-select-selection-model!
at NullInjector.get (http://localhost:4200/vendor.js:8736:27)
at R3Injector.get (http://localhost:4200/vendor.js:24378:33)
at R3Injector.get (http://localhost:4200/vendor.js:24378:33)
at R3Injector.get (http://localhost:4200/vendor.js:24378:33)
at NgModuleRef$1.get (http://localhost:4200/vendor.js:40184:33)
at Object.get (http://localhost:4200/vendor.js:38095:35)
at getOrCreateInjectable (http://localhost:4200/vendor.js:12876:39)
at Module.ɵɵdirectiveInject (http://localhost:4200/vendor.js:28245:12)
at NodeInjectorFactory.NgSelectComponent_Factory [as factory] (http://localhost:4200/lazy-lazy-module.js:4143:398)
at getNodeInjectable (http://localhost:4200/vendor.js:13021:44)
可重现的示例 请参阅 https://github.com/boltex/ivy-lazyload-test 以获取暴露此错误的最小存储库。
复制
1.克隆示例repo git clone https://github.com/boltex/ivy-lazyload-test
2.运行npm install获取所有依赖
3.运行ng serve
预期行为 使用 ng serve 在本地尝试此操作时,当程序在浏览器中加载时,请按“延迟加载模块并在下面添加组件实例”按钮。 (这会将一些组件实例添加到应用程序中)该组件应该有一个 ng-select 。它没有,并且控制台中出现了前面提到的错误。
注意 忽略控制台中的第一个错误:Uncaught TypeError: ng.probe is not a function 使用 angular 9 时出现正常错误,因为如果 window.ng 存在,augury 假定 angular dev 模式处于活动状态,但 ivy 现在不导出探针。
这是截图
我的当前设置 - 操作系统:[Windows 10] - 浏览器 [铬] - 版本 [78.0.3904.108 (正式版) (64-bit)]
感谢您抽出时间关注此问题!
【问题讨论】:
标签: angular lazy-loading angular-ngselect angular-ivy