@NgModule

@NgModule 的使用方式
看一个最简单的 @NgModule 的定义:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { TestViewChildComponent } from './test-view-child/test-view-child.component';
import { ChildOneComponent } from './test-view-child/child-one/child-one.component';

@NgModule({
declarations: [
AppComponent,
TestViewChildComponent,
ChildOneComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }


declarations:用来放组件、指令、管道的声明。
imports:用来导入外部模块。
providers:需要使用的 Service 都放在这里。
bootstrap:定义启动组件。你可能注意到了这个配置项是一个数组,也就是说可以指定做个组件作为启动点,但是这种用法是很罕见的。

原文地址:https://www.cnblogs.com/zhouyx/p/14343651.html