Published on: 10/6/20 11:12 AM
Category:Angular Angular 10 Code Tags: Angular, Angular 10, How Angular application starts?In this post we are going to take look on how angular application starts.
For any angular application, entry point is index.html
. In index.html
file there is tag called as <app-root>
<!--index.html-->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Angular</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
In main.ts file <app-root>
selector is picked up by the AppModule.
Below is code snippet from main.ts
file
//main.ts
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));
AppModule is module which is bootstrapped this means specified module is going to load first in our angular application.
AppModule can be found in app folder (AppName/src/app/app.module.ts
)
In app.module.ts
file, we need to specify bootstrap array. Component listed here are automatically added as entry component.
As shown in code below App component is bootstrapped, so App Component will be added as entry component.
//bootstrap: [AppComponent]
Below is app.module.ts file for reference, there you can see AppComponent is bootstrapped.
//app.module.ts
@NgModule({
declarations: [AppComponent, HeaderComponent],
imports: [
BrowserModule,
HttpClientModule,
AppRoutingModule,
StoreModule.forRoot(fromapp.appReducer),
EffectsModule.forRoot([AuthEffects,RecipeEffects]),
SharedModule,
CoreModule,
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
App Component will have same selector as <app-root>
,which is specified in it’s app.component.ts file. In app.component.ts file, inside the component decorator selector is specified as "app-root"
//app.component.ts
import { Component} from "@angular/core";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"],
})
export class AppComponent {}
Therefore, template of this component specified in templateUrl
will be rendered in index.html
i.e. app.component.html
In this way angular application starts, please let me know in comment section below if you have any question.
Happy Coding !!
Perfectly indited articles , thankyou for entropy. Babette Keene Sisto
We came across a cool website that you may enjoy. Take a search if you want. Claudette Alisander Senzer
Excellent post! We are linking to this particularly great post on our website. Keep up the good writing. Nicole Wald Weinert
This is one awesome post. Thanks Again. Keep writing. Elene Leonerd Herrle
I am now not sure where you are getting your info, however good topic. Valeda Tally Emanuel
Absolutely indited articles , thanks for selective information . Nisse Falito Hennessey
Your way of telling everything in this paragraph is in fact fastidious, every one be capable of easily be aware of it, Thanks a lot. Aurie Dorie Lukas
Hi friends, its wonderful post about cultureand fully defined, keep it up all the time. Alane Tammy Os
Thanks again for the article. Much thanks again. Really Cool. Janetta Kristoforo Tiffie
I think this internet site has got very excellent indited content material articles. Lilla Gonzalo Clie