Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How the entry(or root) component is loaded?

Tags:

angular

Going by the global convention, lets assume my root component is named as AppComponent with its selector being app-root and root module as AppModule.

AppModule is bootstrapping AppComponent, which I assume, tells angular that this component is my root component.

But in index.html also we call app-root, which again calls the AppComponent.

My question is why do I need to call the entry component in two places(index.html and appModule.ts).Why can't angular guess the root component defined from one place?

PS: i am eagerly looking of answer/suggestions/advice.

Thanks in Advance.

like image 264
radio_head Avatar asked Mar 22 '19 11:03

radio_head


People also ask

How is Angular application loaded?

Here, the bootstrap method starts the Angular application. It refers to AppModule, which looks into the app folders. You can see in the "app. module" file that a bootstrap array which is basically a list of all the components analyzes the index.

Which of the below is used to specify the root component to be loaded?

html file you must specify the root component using it's selector (usually app-root ).

Which component is loaded first in Angular?

Conclusion. So when an Angular application is started, the main. ts file is loaded first, here we bootstrap the root module i.e. app. module.

What is an entry component?

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.


Video Answer


1 Answers

The platformBrowserDynamic().bootstrapModule(AppModule) statement tells Angular which Module to bootstrap (usually the AppModule).

Inside of the bootstrapped Module you have a bootstrap: [AppComponent] statement which defines the Component that will be used to bootstrap the application.

And finally, in your index.html file you must specify the root component using it's selector (usually app-root).

The reason for the last part is so that Angular can actually find the element to be bootstrapped and initialise it. It is not uncommon to wrap your root component in other HTML elements.

like image 94
Darren Ruane Avatar answered Nov 11 '22 08:11

Darren Ruane