Explain metadata object which @NgModule decorator takes in Angular.

976    Asked by SusanConnor in Python , Asked on Jan 3, 2020
Answered by Susan Connor

Components, Services, Directives all are classes in angular 2+. But their expected behavior differs with the decorator (like @NgModule, @Component) declared in their class.

NgModule decorator used to set up angular modules. It’s a notation that says the class is not an ordinary class. It’s a module.

NgModule takes metadata object like imports, declarations, bootstrap, and providers

imports used to import the dependent module like BrowserModule, FormsModule, HttpModule

declaration used to import components

bootstrap defines the root application component

providers defines the services

@NgModule({

  bootstrap: [AppComponent],

  declarations: [

    AppComponent,

    CustomerSelectionComponent,

    ResetPasswordComponent,

    DashboardComponent,

],

imports: [ // import Angular's modules

    BrowserModule,

    FormsModule,

    ReactiveFormsModule,

    HttpModule,

    LoginModule,

],

providers: [ // expose our Services and Providers into Angular's dependency injection

    ENV_PROVIDERS,

    APP_PROVIDERS,

    DatePipe

]

})



Your Answer

Interviews

Parent Categories