1

I was studying about Ngmodule from the official website of the Angular. There, it is written the following statement:

@NgModule takes a metadata object that tells Angular how to compile and launch the application.

I searched on many pages but I am confused about that object. So, can anyone please tell me what is that metadata object which the NgModule takes?

KhiladiBhaiyya
  • 633
  • 1
  • 14
  • 43

1 Answers1

1

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 module. Its a notation that says the class is not an ordinary class. Its a module.

NgModule takes metadata object like imports , declarations , bootstrap , 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
            ]
       }) 

 
Ashraful Islam
  • 1,228
  • 10
  • 13