Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 8: ERROR Error: No component factory found

Tags:

angular

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)

like image 700
garg10may Avatar asked May 31 '19 07:05

garg10may


People also ask

Why can't I find the componentfactory in a service in Angular 6?

}) 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!

Is there a factory for confirmcomponent?

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:

How to fix the component is no in module entrycomponents error?

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.

What is an entry component in angular?

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.


1 Answers

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
]
like image 130
programoholic Avatar answered Oct 19 '22 15:10

programoholic