Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Component cannot be used as an entry component

import { SpinnerComponent, ExternalLibrary } from 'external.library'
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule, ExternalLibrary
  ],
  bootstrap: [AppComponent]
  , entryComponents: [SpinnerComponent]
})

Above is my code to specify entryComponent to a module. also this SpinnerComponent is from an external module which is ExternalModule.

Webpack giving error:

ERROR in SpinnerComponent cannot be used as an entry component.

Is belonging to the same module a requirement for a component to appear in entryComponents property list?

As far as I can go through the official definitions there is no such pre requisite specified for a component before appearing in entryComponent property.

like image 654
Ashutosh Singh Avatar asked Jun 12 '18 13:06

Ashutosh Singh


People also ask

What are entry components?

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.

What is a routed entry component?

Routed entryComponent: This sort of components are declared components and are added as an array inside the declarations section of the app. But, you may need to reference to a component by its class. Router components are not specified explicitly in the HTML of a component but, are registered in routes array.

What is the entry point in Angular?

The angular. module is the entry point of Angular applications. Each application has just one module that gets the rootElement <html> or <body> tag.

What is app component in Angular?

Components are the most basic UI building block of an Angular app. An Angular app contains a tree of Angular components. Angular components are a subset of directives, always associated with a template. Unlike other directives, only one component can be instantiated for a given element in a template.


1 Answers

I was having the same issue. What fixed it for me was adding the component to the entryComponents of a module in my external library.

In your case that would mean updating the ExternalLibrary NgModule to include SpinnerComponent as an entry component instead of the app that's using the library.

@NgModule({
    ...
    entryComponents: [SpinnerComponent]
    ...
})
export class ExternalLibrary { }
like image 137
Josh Raker Avatar answered Sep 19 '22 15:09

Josh Raker