< mat-ripple> ,Angular Directive,用于定义描绘用户互动的区域.
在本章中,我们将展示使用Angular Material绘制波纹效果所需的配置.
以下是修改后的模块描述符的内容 app.module.ts .
来自'@ angular/platform-browser'的
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文件中的变量绑定的各种属性.