< mat-chip-list> ,一个Angular Directive,用于作为芯片的值列表.
在本章中,我们将展示使用Angular Material绘制芯片控件所需的配置.
按照以下步骤更新我们创建的Angular应用程序在 Angular 6 - Project Setup 章节 :
Step | 描述 |
---|---|
1 | 创建一个名为 materialApp 的项目,如 Angular 6 - Project中所述设置章节. |
2 | 修改 app.module.ts , app.component.ts , app.component.css 和 app.component.html 如下所述.保持其余文件不变. |
3 | 编译并运行应用程序以验证实现的逻辑的结果. |
以下是修改后的模块描述符的内容 app.module.ts .
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; import {MatChipsModule} from '@angular/material' import {FormsModule, ReactiveFormsModule} from '@angular/forms'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule, MatChipsModule, FormsModule, ReactiveFormsModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
以下是修改过的HTML主机文件的内容 app.component.html .
<mat-chip-list> <mat-chip>One</mat-chip> <mat-chip>Two</mat-chip> <mat-chip color = "primary" selected>Tree</mat-chip> <mat-chip color = "accent" selected>Four</mat-chip> </mat-chip-list>
验证结果.
首先,我们使用mat-chip-list创建了芯片列表.
然后,我们使用mat-chip为每个芯片列表添加了芯片.