rupesh prajapati
rupesh prajapati

Reputation: 33

How Angular Application Run? which file executes first?

Are main.ts and index.html runs parallelly? if no, which file runs first? if main.ts, then how angular knows that it should display index.html in browser?

Upvotes: 3

Views: 3409

Answers (2)

The Observer
The Observer

Reputation: 155

When someone visits your site index.html will be the first file served. Form here the javascript will be loaded which will then bootstrap Angular. The Angular CLI automatically adds the import for your javascript to index.html during the build (ng build). Build your application and look in your build directory (dist/ by default) you will find the index.html and inside it there will be some script tags: something like: <script src="main.123.js"></script>. This is the compiled version of main.ts and is how main.ts is loaded and executed in your application.

You can see how the angular app is structured here: https://angular.io/guide/file-structure. If you find index.html on this page it explains how this is the entrypoint to your app.

Upvotes: 1

PierreD
PierreD

Reputation: 933

https://dev.to/casperns/how-angular-trigger-indexhtml-and-start-working-1l46

  • Angular started with main.ts.
  • Then we bootstrap an angular application and we pass app.module.ts as an argument. In app.module.ts we tell angular: "There is the app component which you should know when you try to start yourself".
  • And angular now analyze this app component, reading the set up we pass there and there is SELECTOR app-root.
  • Now, angular is enable to handle app-root in the index.html and knows rules for the SELECTOR.
  • SELECTOR should insert the app components and have some HTML code - a template attached to him - html component.
  • This is how Angular application starts.

Upvotes: 2

Related Questions