是否可以创建带有连字支持的自定义材质图标。我目前svgIcon
用于获取自定义图标,有没有办法实现连字支持的自定义图标?
我当前的代码片段如下
app.component.ts
import { Component } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { MatIconRegistry } from '@angular/material';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'app';
constructor(
iconRegistry: MatIconRegistry,
sanitizer: DomSanitizer
) {
iconRegistry.addSvgIcon('key',
sanitizer.bypassSecurityTrustResourceUrl('assets/icons/key.svg')
);
iconRegistry.addSvgIcon('user',
sanitizer.bypassSecurityTrustResourceUrl('assets/icons/user.svg')
);
}
}
login.component.html
<mat-form-field>
<input matInput placeholder="Username" formControlName="username">
<mat-icon matPrefix svgIcon="user"></mat-icon>
<mat-error *ngIf="username.invalid">Username is required</mat-error>
</mat-form-field>
<mat-form-field>
<input matInput type="password" placeholder="Password" formControlName="password">
<mat-icon matPrefix svgIcon="key"></mat-icon>
<mat-error *ngIf="password.invalid">Password is required</mat-error>
</mat-form-field>