Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 16, 2022 07:51 am GMT

How Angular Application Starts - Behind The $cene story!

Today we will learn the application flow in Angular.
What happens when the application starts.

It would be a theory but again an important one if you want to master Angular.

1 angular.json

When you open up your angular project you might have noticed a file sitting at the project root - angular.json
Image description
It is a very important file and contains several important configuration information to run the angular application.
A detailed overview I will provide on this very soon.

When the application first starts Angular looks for this file.

So now if you open the file you will find a node called main under
architect -> build -> options , you would see a main node
Image description
Once Angular found the file it starts looking for the main node.
The value of the main node is a file path that Angular is looking for - the main.ts under src folder.

2 main.ts
This is the main entry point. As an analogy if you have a prior knowledge of C/ C++/ Java you must have seen there also that main is the starting point.
The main.ts file is present under the src folder.
Image description

import { enableProdMode } from '@angular/core';import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';import { AppModule } from './app/app.module';import { environment } from './environments/environment';if (environment.production) {  enableProdMode();}platformBrowserDynamic().bootstrapModule(AppModule)  .catch(err => console.error(err));

platformBrowserDynamic creates the platform. This function is also used to bootstrap the Angular Application. Here we specify the first module that should be loaded when the application starts for the first time - the root module. In other words the bootstrapping module.

3 app.module.ts
Once angular finds the starting module the app.module.ts (where all the components/ directives/ pipes associated to this module is present and dependency to other module is also present) it looks for the bootstrap option -
Image description
Where the starting component name has been specified - in this case the AppComponent.

By now Angular compiler has all the required information it needs to work.

4 index.html
Now the index.html is loaded and starts parsing. Once it finds the selector it exactly knows which component to load and the AppComponent is displayed in the screen.

And that's it. This is how the application starts.

Hope you enjoyed reading the post

If you liked it please like share comment .

Coming up more topics on Angular.
So stay tuned.

I will be tweeting more on Angular JavaScript TypeScript CSS tips and tricks.

So hope to see you there too

Cheers
Happy Coding


Original Link: https://dev.to/this-is-angular/how-angular-application-works-behind-the-cene-story-1i21

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To