I am getting the following error in Console of Plunker:
No component factory found for undefined. Did you add it to @NgModule.entryComponents?
But I did add the component (SecondComp) to entryComponents in @NgModule. Please take a look at this plnkr and let me know, why am I getting this error?
https://plnkr.co/edit/BM3NMR?p=preview
//our root app component
import {Component, NgModule, VERSION} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {FirstComp} from './first.component'
import {SecondComp} from './second.component'
import {InjService} from './inj.service'
@Component({
selector: 'my-app',
template: `
<div>
<h2>Hello {{name}}</h2>
</div>
<first-comp></first-comp>
`,
})
export class App {
name:string;
constructor() {
this.name = `Angular! v${VERSION.full}`
}
}
@NgModule({
imports: [ BrowserModule ],
providers: [ InjService ],
declarations: [ App, FirstComp, SecondComp ],
bootstrap: [ App ],
entryComponents: [ SecondComp ],
})
export class AppModule {}
Thank you!
There's a simple spelling problem in your
inj.service.ts. You speltSecondCompasSecondComponent. ChangingSecondComponenttoSecondCompfixed the issue, as well as uncommenting the lines in youraddDynamicComponentmethod.inj.service.ts:Before
After
Updated Plnkr