< mat-button> ,一个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 {MatButtonModule,MatIconModule} from '@angular/material' import {FormsModule, ReactiveFormsModule} from '@angular/forms'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule, MatButtonModule,MatIconModule, FormsModule, ReactiveFormsModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
以下是修改过的CSS文件的内容 app.component.css .
.tp-button-row button, .tp-button-row a { margin-right: 8px; }
以下是修改过的HTML主机文件的内容 app.component.html .
<div class = "example-button-row"> <button mat-button>Basic</button> <button mat-raised-button>Raised</button> <button mat-stroked-button>Stroked</button> <button mat-flat-button>Flat</button> <button mat-icon-button> <mat-icon aria-label="Heart">favorite</mat-icon> </button> <button mat-fab>Fab</button> <button mat-mini-fab>Mini</button> <a mat-button routerLink = ".">Link</a> </div>
验证结果.
在这里,我们使用各种mat-buttons变体创建了按钮.