difference between bootstrap and entryComponent in Angular2+

Viewed 3706

I am learning Angular and I came across a scenario where in one module component is declared in bootstrap while in another few components are listed in entryComponent array in @Ngmodule metadata. Kindly help me out in understanding the concept.

Any help is much appreciated.

Thank you !!!

3 Answers

Straight from the documentation:

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.

So this means that any component you have in the bootstrap array, or have defined in a route, is immediately an entryComponent. This is because you do not reference these inside any template. This prevents the compiler to treeshake these components out of the module.

Further:

A bootstrapped component is an entry component that Angular loads into the DOM during the bootstrap process (application launch). Other entry components are loaded dynamically by other means, such as with the router.

Though these two mechanisms account for most entry components, if your app happens to bootstrap or dynamically load a component by type imperatively, you must add it to entryComponents explicitly.

bootstrap is for bootstraping components, which mainly means that the components that your bootstrap are the entre point of your application (such as AppComponent).

entryComponents are components that can be dynamically loaded through a ComponentFactoryResolver. If they're not in the entry components, loading them will throw an error.

Related