I have created two components in the same ts file as below. Was referring the example code from https://material.angular.io/components/dialog/examples and it uses the same approach.
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogModule, MatDialog, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
@Component({
selector: 'app-srapi',
templateUrl: './srapi.component.html',
styleUrls: ['./srapi.component.scss']
})
export class SrapiComponent {
constructor(private dialog: MatDialog) { }
onCreate(): void {
const dialogRef = this.dialog.open(SrapiTFLFormComponent);
}
}
@Component({
selector: 'app-srapi-tfl-form',
templateUrl: './srapi-tfl-form.html'
})
export class SrapiTFLFormComponent{
constructor(public dialogRef: MatDialogRef<SrapiTFLFormComponent>) {}
}
Also declared and imported both of these in app.module.ts
import { SrapiComponent, SrapiTFLFormComponent } from './srapi/srapi.component';
@NgModule({
declarations: [
AppComponent,
LoginComponent,
HeaderComponent,
FooterComponent,
RegisterComponent,
EdcUserFormComponent,
SidebarComponent,
EdcMasterDataComponent,
SrapiComponent,
SrapiTFLFormComponent
],
imports: [
BrowserModule,
.
.
but it gives an error when it opens the dialog.
ERROR Error: No component factory found for SrapiTFLFormComponent. Did you add it to @NgModule.entryComponents? at noComponentFactoryError (core.js:15705)
}) TL;DR: A service in ng6 with providedIn: "root" cannot find the ComponentFactory when the Component is not added in the entryComponents of app.module. This problem can also occur if you are using angular 6 in combination with dynamically creating a Component in a service!
No component factory found for ConfirmComponent. Did you add it to @NgModule.entryComponents? The component is declared in app.module.server.ts I have also app.module.browser.ts and app.module.shared.ts How can I fix that? if ConfirmComponent is in another module, you need to export it there thus you can use it outside, add:
This error occur when you try to load a component dynamically and: The component is no in module entryComponents. To fix this error you can add a router to the component or add it to entryComponents of module. Add a router to component.drawback of this approach is your component will be accessible with that url.
An entry component is any component that Angular loads imperatively, (which means you’re not referencing it in the template), by type. You specify an entry component by bootstrapping it in an NgModule, or including it in a routing definition above code was absent so I got a such error as here described, the same.
in your app.module.ts
add below code :
import { SrapiComponent, SrapiTFLFormComponent } from './srapi/srapi.component';
@NgModule({
declarations: [
AppComponent,
LoginComponent,
HeaderComponent,
FooterComponent,
RegisterComponent,
EdcUserFormComponent,
SidebarComponent,
EdcMasterDataComponent,
SrapiComponent,
SrapiTFLFormComponent
],
imports: [
BrowserModule,
.
.
],
entryComponents: [
SrapiTFLFormComponent
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With