Skip to main content
<FrontBackGeek/>
angular-icon

How angular app works? what happen in background when angular application starts.

FrontBackGeek 3 years ago

Let’s understand how an angular application works from core, what happen when it starts.

In index.html file there is a <app-root> custom html code, this app-root is a selector of app component of application.

During the build process the whole application build is generated and this script filess added to the bottom of index.html files.

app component is connected to the index.html file through its app-root selector.

This app-root selector scope the content of app component html file to index.html file.

In the app.module.ts file we declare this app component and also bootstrap it.

 declarations: [AppComponent],
 bootstrap: [AppComponent]

We can only bootstrap one component at a time to make it a root component.

But we can declare multiple components and connect them to each other.

How it start the angular application ?

In main.ts (it execute first) file platformBrowserDynamic() function executes and it start the angular application in browser then we call another function bootstrapModule() function.

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.error(err));

Here we pass the link of our own module which is AppModule in this case.

We pass this as an argument and this say angular to start the application.

Now angular parse this module

Register the components which are declared

Import some other modules.

detects bootstrap array and looks for selector of this components.

© FrontBackGeek.com 2021 All Rights Reserved. DMCA.com Protection Status