0
我有一個小方法,使用Compiler
類('@angular/core')
和compileModuleAndAllComponentsAsync()
方法創建一個組件。當我創建組件,具有下列錯誤沒有提供當compileModuleAndAllComponentsAsync()angular2 - 2.0最終版本
無提供者名稱服務「
我知道這是什麼錯誤,但我嘗試編譯模塊有這個提供商:!
@NgModule({
imports: [CommonModule, RouterModule, FormsModule],
declarations: [MyComponent],
providers: [NameService]
})
export class MyModule {}
所以,我怎麼能在組件上注入提供商NameService
和其他供應商正在創建?
this.compiler.compileModuleAndAllComponentsAsync(this._createDynamicComponent())
.then(factory => {
const compFactory = factory.componentFactories.find((x: any) => x.componentType === this.instanceComponent());
const cmpRef = this.vcRef.createComponent(compFactory);
this.addToInstance(cmpRef, (cmpRef) => {
cmpRef.destroy();
});
});