【问题标题】:Lazy-loading with Angular Ivy : No provider for InjectionToken ng-select-selection-model使用 Angular Ivy 进行延迟加载:InjectionToken ng-select-selection-model 没有提供者
【发布时间】: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


    【解决方案1】:

    我找到了一个使用@HeroDev 的“英雄加载器”组件的解决方案。 (有关它使用的其他技术,请参阅他们相对较短的源代码:https://github.com/herodevs/herodevs-packages/tree/master/projects

    我使用的方法与通过延迟加载将组件、第 3 方或其他方式集成到现有应用程序中的所有方法不完全兼容。 (不使用路由)

    我更新了我的存储库https://github.com/boltex/ivy-lazyload-test,其中包含一个工作示例,您可以在其中添加和删除任意数量的不同模块和组件到打开的应用程序中,而无需更改路由。

    【讨论】:

      猜你喜欢
      • 2019-04-18
      • 1970-01-01
      • 2020-06-12
      • 2018-09-01
      • 2017-07-24
      • 2018-07-16
      • 2021-02-24
      • 1970-01-01
      • 2018-03-24
      相关资源
      最近更新 更多