Which File Runs First In An Angular 4 App When I Run The App?
Solution 1:
In Angular app,
Index.html
is the start and it then main.ts
After Index.html
, main.ts
. Which tells which file to run. Which is mainly to bootstrap
main.ts
is the entry point of your application, compiles the application with just-in-time and bootstraps the application .Angular can be bootstrapped in multiple environments we need to import a module specific to the environment. in which angular looks for which module would run first.
// The browser platform with a compilerimport { platformBrowserDynamic } from'@angular/platform-browser-dynamic';
// The app moduleimport { AppModule } from'./app/app.module';
Look at the following diagram which explains the structure very well.
Solution 2:
angular.json -> angular-cli configuration file main.ts -> Angular module bootstrap application file. Set the entry module for your application. app.module.ts -> Based upon your entry module, it configures which component will load first from that module and what others dependency modules, components, pipes, services.
Solution 3:
Only one thing which is stranger, if you add a 'console.log' before '@Component({' of 'app.component.ts', you will find that one will be called first.
beacause angular does not work in asynchronously.angular follow non-blocking
Solution 4:
Started from index.html and set title and then go to body tag and that is selector of app component, Whenever ng-serve builds our application, it creates “bundles” and automatically adds these to our index.html file at runtime. So, from these bundles, the first code has to be executed from “main.ts” file, i.e., “main.ts” file is the main file from where the execution of an Angular application will start. then call bootstrap method that will call appModule, and list of component that grouped into appModule will load
Post a Comment for "Which File Runs First In An Angular 4 App When I Run The App?"