前言
Angular 2.x 4.x 5.x 的逐个版本,遵循了模块化的思想,架构以及应用,相对于1.x的版本有了很大的改进,从项目中的使用来看,有很大的提升,今天我们就来看一下Angular 5.x架构的精髓所在。
主要的构造块
Angular整体来讲我们主要会学习到八个主要的构造块,分别为模块,组件,模板,元数据,数据绑定,指令,服务,依赖注入,下面逐个来解释一下:
模块
对于模块而言,整个应用至少存在一个根模块,模块是以@NgModule装饰器的一个类,比如如下代码:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { DashboardComponent } from './dashboard.component';
import { HeroDetailComponent } from './hero-detail.component';
import { HeroesComponent } from './heroes.component';
import { HeroService } from './hero.service';
import { AppRoutingModule } from './app-routing.module';
@NgModule({
imports: [
BrowserModule,
FormsModule,
AppRoutingModule
],
declarations: [
AppComponent,
DashboardComponent,
HeroDetailComponent,
HeroesComponent
],
providers: [ HeroService ],
bootstrap: [ AppComponent ]
})
e