@NgModule({declarations: [], // 用到的组件,指令,管道providers: [], // 依赖注入服务 imports: [], // 导入需要的模块exports: [], // 导出的模块,跨模块交流entryComponents: [],// 需提前编译好的模块bootstrap: [] // 设置根组件
})
export class AppModule { }
declarations
- 声明本模块中拥有的视图类。Angular 有三种视图类:组件 指令和管道
providers
- 服务的创建者,并加入到全局服务列表中,可用于应用任何部分
imports
exports
- declarations的子集可用于其它模块的组件模板。
bootstrap
- 指定应用的主视图(根组件)它是其它视图的宿主。只有根模块才能设置bootstrap属性。
angular 提供的模块
@angular/core
- NgModule:模块定义装饰器
- Component:组件定义装饰器
- Directive:指令定义装饰器
- Pipe :管道定义装饰器
- PipeTransform:管道接口
- Injectable:服务定义装饰器
- ElmentRef:元素引用
- ViewChild:获取子元素
- Render:渲染
- Input:接受参数输入
- Output:事件输出
- EventEmitter:触发自定义事件
@angular/common
- CommonModule:通用模块,包含内置指令ngIf,ngFor
@angular/forms
- FormsModule:定义模版驱动表单
- ReactiveFormsModule:定义响应式表单
- FormGroup, FormArray, FormControl, FormBuilder:响应式表单元素
- Validators:表单校验
@angular/http
@angular/router
- RouterModule 路由模块
- Routes 路由数据结构
@angular/platform-browser
- platformBrowser:AoT编译
- BrowserModule:浏览器支持,注意该模块导入了CommonModule,然后导出去,所以引用了这个模块也就引用了CommonModule
@angular/platform-browser-dynamic
- platformBrowserDynamic:JIT编译