1

我使用 Angular CLI 创建了“库”类型的项目。

在里面,我有组件 MyComponent ,里面有以下构造函数:

constructor(private componentFactoryResolver: ComponentFactoryResolver) {      }

MyComponent 在其模块中注册(声明和导出)。该模块还导入“CommonModule”。

但是,一旦我尝试在另一个应用程序中使用这个库(内置版本),我会得到以下信息:

NullInjectorError: StaticInjectorError(AppModule)[MyComponent -> ComponentFactoryResolver]: 
  StaticInjectorError(Platform: core)[MyComponent -> ComponentFactoryResolver]: 
    NullInjectorError: No provider for ComponentFactoryResolver!
    at NullInjector.get (http://localhost:4200/vendor.js:97227:27)
    at resolveToken (http://localhost:4200/vendor.js:112144:24)
    at tryResolveToken (http://localhost:4200/vendor.js:112070:16)
    at StaticInjector.get (http://localhost:4200/vendor.js:111920:20)
    at resolveToken (http://localhost:4200/vendor.js:112144:24)
    at tryResolveToken (http://localhost:4200/vendor.js:112070:16)
    at StaticInjector.get (http://localhost:4200/vendor.js:111920:20)
    at resolveNgModuleDep (http://localhost:4200/vendor.js:123107:29)
    at NgModuleRef_.get (http://localhost:4200/vendor.js:124173:16)
    at resolveDep (http://localhost:4200/vendor.js:124704:45)

我试过这个但没有帮助:Angular 6 custom lib No provider for ComponentFactoryResolver

版本

角 CLI:8.3.10

节点:10.14.2

操作系统:达尔文 x64

角度:8.2.11

4

0 回答 0