An NgModule describes how the application parts fit together. Every application has at least one Angular module, the root module that you bootstrap to launch the application. By convention, it is usually called
AppModule.
If you use the Angular CLI to generate an app, the default
AppModule is as follows:
- /* JavaScript imports */
- import { BrowserModule } from '@angular/platform-browser';
- import { NgModule } from '@angular/core';
- import { FormsModule } from '@angular/forms';
- import { HttpClientModule } from '@angular/common/http';
-
- import { AppComponent } from './app.component';
-
- /* the AppModule class with the @NgModule decorator */
- @NgModule({
- declarations: [
- AppComponent
- ],
- imports: [
- BrowserModule,
- FormsModule,
- HttpClientModule
- ],
- providers: [],
- bootstrap: [AppComponent]
- })
- export class AppModule { }
After the import statements is a class with the
@NgModule decorator.
The
@NgModule decorator identifies AppModule as an NgModule class. @NgModule takes a metadata object that tells Angular how to compile and launch the application.- declarations—this application's lone component.
- imports—import
BrowserModuleto have browser specific services such as DOM rendering, sanitization, and location. - providers—the service providers.
- bootstrap—the root component that Angular creates and inserts into the host
index.htmlweb page.
The default application created by the Angular CLI only has one component,
AppComponent, so it is in both the declarations and the bootstrap arrays.
0 comments:
Post a Comment