Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : No Component Factory Found. Did you add it to @NgModule.entryComponents?

I am trying to create a popover on my Home Page.So I have created following function..

public presentPopover(myEvent) {
    let popover = this.popoverCtrl.create(TestComponent);
    popover.present({
      ev: myEvent
    });
  }

in my homepage.module.ts i have added testComponent as entry component.

import { TestModule } from './../../components/test/test.module';
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { HomePage } from './home';
import { TestComponent } from './../../components/test/test';

@NgModule({
  declarations: [
    HomePage,
  ],
  imports: [
    TestModule,
    IonicPageModule.forChild(HomePage),
  ],
  entryComponents: [
    TestComponent,
  ]
})

But i am still getting this error wheni click that popover button.

ERROR Error: Uncaught (in promise): Error: No component factory found for TestComponent. Did you add it to @NgModule.entryComponents?
Error: No component factory found for TestComponent. Did you add it to @NgModule.entryComponents?
    at noComponentFactoryError (core.js:3786)
    at CodegenComponentFactoryResolver.resolveComponentFactory (core.js:3850)
    at PopoverCmp._load (popover-component.js:41)
    at PopoverCmp.ionViewPreLoad (popover-component.js:33)

And I am confused why should I add this to entry Components?

like image 336
CuriousAboutThings Avatar asked Nov 22 '17 19:11

CuriousAboutThings


People also ask

What is Entrycomponents in angular NgModule?

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.

How do you do Entrycomponents?

The entryComponent is the component which loads angular by force, that means these components are not referenced in the HTML template. In most of the cases, Angular loads a component when it is explicitly declared in the component template.

What is angular Componentfactoryresolver?

ComponentFactoryResolverlinkA simple registry that maps Components to generated ComponentFactory classes that can be used to create instances of components. Use to obtain the factory for a given component type, then use the factory's create() method to create a component of that type.


1 Answers

You need to add dynamically created components to entry components inside your @NgModule

@NgModule({
  ...
  declarations: [
    ...
    Name of your component,
  ],
  entryComponents: [
    ...
    Name of your component,    
  ]
})

Note: In some cases entry components under lazily loaded modules will not work, as a workaround put them in your app.module (root)

like image 119
arun kumar Avatar answered Oct 06 '22 08:10

arun kumar