- Angular Material 7 教程
- Angular Material 7 - 首頁
- Angular Material 7 - 概述
- 環境設定
- 表單控制元件
- Angular Material 7 - 自動完成
- Angular Material 7 - 複選框
- Angular Material 7 - 日期選擇器
- Angular Material 7 - 表單欄位
- Angular Material 7 - 輸入框
- Angular Material 7 - 單選按鈕
- Angular Material 7 - 選擇器
- Angular Material 7 - 滑塊
- Angular Material 7 - 開關滑塊
- 導航
- Angular Material 7 - 選單
- Angular Material 7 - 側邊導航欄
- Angular Material 7 - 工具欄
- 佈局
- Angular Material 7 - 卡片
- Angular Material 7 - 分隔線
- Angular Material 7 - 展開面板
- Angular Material 7 - 網格列表
- Angular Material 7 - 列表
- Angular Material 7 - 步進器
- Angular Material 7 - 標籤頁
- Angular Material 7 - 樹形結構
- 按鈕和指示器
- Angular Material 7 - 按鈕
- Angular Material 7 - 按鈕切換
- Angular Material 7 - 徽章
- Angular Material 7 - 晶片
- Angular Material 7 - 圖示
- Angular Material 7 - 進度旋轉器
- Angular Material 7 - 進度條
- Angular Material 7 - 水波紋效果
- 彈出框和模態框
- Angular Material 7 - SnackBar
- Angular Material 7 - 工具提示
- 資料表格
- Angular Material 7 - 分頁器
- Angular Material 7 - 排序表頭
- Angular Material 7 - 表格
- Angular Material 7 資源
- Angular Material 7 - 快速指南
- Angular Material 7 - 資源
- Angular Material 7 - 討論
Angular Material 7 - 步進器
<mat-stepper> 是一個 Angular 指令,用於建立類似嚮導的工作流程步驟。
本章將展示使用 Angular Material 繪製步進器控制元件所需的配置。
建立 Angular 應用
按照以下步驟更新我們在Angular 6 - 專案設定章節中建立的 Angular 應用程式:
| 步驟 | 描述 |
|---|---|
| 1 | 按照Angular 6 - 專案設定章節中的說明,建立一個名為materialApp的專案。 |
| 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 {MatStepperModule, MatInputModule, MatButtonModule} from '@angular/material'
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
MatStepperModule, MatInputModule, MatButtonModule,
FormsModule,
ReactiveFormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
以下是修改後的 HTML 主檔案app.component.html的內容。
<mat-horizontal-stepper [linear] = "isLinear" #stepper>
<mat-step [stepControl] = "firstFormGroup">
<form [formGroup] = "firstFormGroup">
<ng-template matStepLabel>Enter your name</ng-template>
<mat-form-field>
<input matInput placeholder = "Last name, First name" formControlName = "firstCtrl" required>
</mat-form-field>
<div>
<button mat-button matStepperNext>Next</button>
</div>
</form>
</mat-step>
<mat-step [stepControl] = "secondFormGroup">
<form [formGroup] = "secondFormGroup">
<ng-template matStepLabel>Enter your address</ng-template>
<mat-form-field>
<input matInput placeholder = "Address" formControlName = "secondCtrl" required>
</mat-form-field>
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button matStepperNext>Next</button>
</div>
</form>
</mat-step>
<mat-step>
<ng-template matStepLabel>Done</ng-template>
Details taken.
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button (click) = "stepper.reset()">Reset</button>
</div>
</mat-step>
</mat-horizontal-stepper>
以下是修改後的 ts 檔案app.component.ts的內容。
import { Component } from '@angular/core';
import { FormControl } from "@angular/forms";
import { FormGroup } from "@angular/forms";
import { FormBuilder } from "@angular/forms";
import { Validators } from "@angular/forms";
export interface Food {
value: string;
display: string;
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'materialApp';
firstFormGroup: FormGroup;
secondFormGroup: FormGroup;
constructor(private _formBuilder: FormBuilder) {}
ngOnInit() {
this.firstFormGroup = this._formBuilder.group({
firstCtrl: ['', Validators.required]
});
this.secondFormGroup = this._formBuilder.group({
secondCtrl: ['', Validators.required]
});
}
}
結果
驗證結果。
詳情
- 首先,我們使用 mat-stepper 建立了步進器。
- 然後,我們使用 mat-step 添加了內容。
廣告