@NgModule 装饰器接受 Angular 的那个元数据对象是什么?

What is that metadata object which @NgModule decorator takes in Angular?

我是从Angular的官方网站学习Ngmodule的。在那里,写了以下语句:

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

我搜索了很多页面,但我对那个对象感到困惑。那么,谁能告诉我 NgModule 使用的元数据对象是什么?

组件、服务、指令在 angular 2+ 中都是 class。但是它们的预期行为与在 class.

中声明的装饰器(如 @NgModule@Component)不同

NgModule 装饰器用于设置 angular 模块。它表示 class 不是普通的 class。它是一个模块。

NgModule 接受像 imports , declarations , bootstrap , providers

这样的元数据对象
  • imports 用于导入依赖模块,如BrowserModuleFormsModuleHttpModule
  • declaration 用于导入组件
  • bootstrap 定义根应用程序组件
  • providers 定义服务


     @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
            ]
       })