Adding app module

In the preceding section, we created an Angular component named AppComponent. Now we need to bootstrap this AppComponent so that Angular will consider this as a root component of the application. We can bootstrap a component by decorating an AppModule class with the NgModule and adding the metadata bootstrap assigned with AppComponent. Follow these steps to create AppModule:

  1. Create a TypeScript by right-clicking on the app folder and navigating to Add | New Item. Select Scripts under Web from the left-hand side pane and select TypeScript File from the middle pane. Add a file named app.module.ts, and click on Add:
Adding the TypeScript file named app.module.ts
  1. Add the following code snippet to app.module.ts:
      import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-
browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule,
FormsModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }

Here, we added AppComponent as root component and imported BrowserModule as our application will be consumed via browser and FormsModule two bindings.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.5.239