我使用angularcli创建了“library”类型的项目。
在内部,我有组件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
角度:8.2.11