What is ngModule in angular 4
An NgModule is a class marked by the
An NgModule is a class marked by the
@NgModule
decorator. @NgModule
takes a metadata object that describes how to compile a component's template and how to create an injector at runtime.
NgModule metadata does the following:
- Declares which components, directives, and pipes belong to the module.
- Makes some of those components, directives, and pipes public so that other module's component templates can use them.
- Imports other modules with the components, directives, and pipes that components in the current module need.
- Provides services that the other application components can use.
The basic NgModule
The CLI generates the following basic app module when creating a new app.
// imports
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { ItemDirective } from './item.directive';
// @NgModule decorator with its metadata
@NgModule({
declarations: [
AppComponent,
ItemDirective
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
0 comments:
Post a Comment