私はCompiler
クラス('@angular/core')
とcompileModuleAndAllComponentsAsync()
メソッドを使用してコンポーネントを作成する少しの方法があります。私は、コンポーネントを作成すると、compileModuleAndAllComponentsAsync()angle2 - 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();
});
});