Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between bootstrap and entryComponent in Angular2+

Tags:

angular

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

like image 659
Apurva Pathak Avatar asked Sep 07 '18 06:09

Apurva Pathak


People also ask

What is bootstrap in NgModule?

The bootstrap property or key of the NgModule decorator specifies which component should be loaded by Angular when the app-level module loads. Angular reads the bootstrap metadata and loads the app-level component, called AppComponent .

What is Entrycomponent 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.

Can we bootstrap multiple module in Angular?

You can combine multiple modules into single modules and your angular app will be automatically initialized for newly created module and other modules will act as dependent modules for newly created module.

What is meant by bootstrapping an Angular application?

Bootstrapping is a technique of initializing or loading our Angular application. let's walk through our code created in Create your First new Angular project and see what happens at each stage and how our AppComponent gets loaded and displays “app works!”. The Angular takes the following steps to load our first view.


1 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.

like image 156
Poul Kruijt Avatar answered Oct 22 '22 00:10

Poul Kruijt