
- 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-ripple> 是一個 Angular 指令,用於定義一個表示使用者互動的區域。
本章將展示使用 Angular Material 繪製水波紋效果所需的配置。
以下是修改後的模組描述符檔案 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 {MatRippleModule, MatCheckboxModule, MatInputModule} from '@angular/material' import {FormsModule, ReactiveFormsModule} from '@angular/forms'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule, MatRippleModule, MatCheckboxModule, MatInputModule, FormsModule, ReactiveFormsModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
以下是修改後的 HTML 主機檔案 app.component.html 的內容。
<mat-checkbox [(ngModel)] = "centered" class = "tp-ripple-checkbox">Centered</mat-checkbox> <mat-checkbox [(ngModel)] = "disabled" class = "tp-ripple-checkbox">Disabled</mat-checkbox> <mat-checkbox [(ngModel)] = "unbounded" class = "tp-ripple-checkbox">Unbounded</mat-checkbox> <section> <mat-form-field class = "tp-ripple-form-field"> <input matInput [(ngModel)] = "radius" type = "number" placeholder = "Radius"> </mat-form-field> <mat-form-field class = "tp-ripple-form-field"> <input matInput [(ngModel)] = "color" type = "text" placeholder = "Color"> </mat-form-field> </section> <div class = "tp-ripple-container mat-elevation-z4" matRipple [matRippleCentered] = "centered" [matRippleDisabled] = "disabled" [matRippleUnbounded] = "unbounded" [matRippleRadius] = "radius" [matRippleColor] = "color"> Click me </div>
以下是修改後的 CSS 檔案 app.component.css 的內容。
.tp-ripple-container { cursor: pointer; text-align: center; width: 300px; height: 300px; line-height: 300px; user-select: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: transparent; } .tp-ripple-checkbox { margin: 6px 12px 6px 0; } .tp-ripple-form-field { margin: 0 12px 0 0; }
以下是修改後的 ts 檔案 app.component.ts 的內容。
import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'materialApp'; centered = false; disabled = false; unbounded = false; radius: number; color: string; }
結果
驗證結果。

詳情
首先,我們使用 mat-checkbox 建立了複選框,並使用 ngModel 將其與變數繫結。這些屬性將用於自定義水波紋效果。
然後,我們建立了水波紋效果,並展示了其與 .ts 檔案中變數繫結的各種屬性。
廣告