目录

angular2 - 建筑( Architecture)

以下屏幕截图显示了Angular 2应用程序的解剖结构。 每个应用程序都包含组件。 每个组件都是应用程序功能的逻辑边界。 您需要具有分层服务,这些服务用于跨组件共享功能。

解剖学

以下是组件的解剖结构。 一个组成部分包括 -

  • Class - 这类似于C ++或Java类,它由属性和方法组成。

  • Metadata - 用于装饰类并扩展类的功能。

  • Template - 用于定义应用程序中显示的HTML视图。

零件

以下是组件的示例。

import { Component } from '@angular/core';
@Component ({ 
   selector: 'my-app', 
   templateUrl: 'app/app.component.html' 
}) 
export class AppComponent { 
   appTitle: string = 'Welcome';
} 

每个应用程序都由模块组成。 每个Angular 2应用程序都需要一个Angular Root Module。 然后,每个Angular Root模块可以有多个组件来分隔功能。

功能

以下是根模块的示例。

import { NgModule }      from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { AppComponent }  from './app.component';  
@NgModule ({ 
   imports:      [ BrowserModule ], 
   declarations: [ AppComponent ], 
   bootstrap:    [ AppComponent ] 
}) 
export class AppModule { } 

每个应用程序都由功能模块组成,其中每个模块都具有应用程序的单独功能。 然后,每个角度特征模块可以具有多个组件来分离功能。

每个申请
↑回到顶部↑
WIKI教程 @2018