angular - 错误类型错误:iconName.split 不是函数
问题描述
无法显示 svgIcon。我将 iconName 作为 svgIcon 中的输入。
名称,价格是显示如果删除正常工作<mat-icon>
。
显示如下错误:
TypeError:iconName.split 不是 MatIcon.push../node_modules/@angular/material/esm5/icon.es5.js.MatIcon._splitIconName 的函数
app.component.ts
getList(): ItemModel[] {
const dataList: ItemModel[] = [];
// let dataKey: string[] = [];
const tempSanitizer = this.sanitizer;
const tempService = this.service;
Object.keys(this.service.dataSource).forEach( (key: string) => {
dataList.push(this.service.dataSource[key]);
// if (!tempService.dataSource.hasOwnProperty(key)) {
// console.log(key);
// }
// console.log(tempService.dataSource[key].icon);
this.iconRegistery.addSvgIcon(
key,
tempSanitizer.bypassSecurityTrustResourceUrl(tempService.dataSource[key].icon)
);
}
);
return dataList;
}
app.component.html
<app-grid-beer [title]="'Top Weekly'" [itemList]="getList()"></app-grid-beer>
<!-- [dataSource]="" -->
<app-grid-beer [title]="'Ever Green'" [itemList]="getList()"></app-grid-beer>
网格啤酒.component.html
<mat-grid-tile *ngFor="let item of itemList">
<div fxLayout="column" fxLayoutGap="5px" fxLayoutAlign="center center">
<mat-icon [svgIcon]="item.id" class="section-icon-height"></mat-icon>
<span>{{item.id}}</span>
<mat-label class="subtitle-1">{{item ? item.name : ''}}</mat-label>
<label class="h6-header"><mat-icon svgIcon="rupee" class="rupee-icon"></mat-icon>{{item ? item.price : '' }}</label>
</div>
</mat-grid-tile>
解决方案
推荐阅读
- swift - 放大 GraphQL 错误未授权访问创建
- c# - 如何在调试中运行 .NET CORE MVC
- java - 非标准 Java 安装错误地报告了默认语言环境
- kubernetes - EKS 中同一命名空间中 K8s pod 的时钟同步
- python - 将 TopoDS_Shell 转换为 bsplinesurface
- mongodb - mongoimport 未被识别为内部或外部命令
- python - 变量名决定Keras load_model的成败(Lambda层问题)
- javascript - 您将如何向接受参数的用户提供 API 端点?(GrapQL/ApolloServer)
- javascript - 从 crypto.createHash() 获取不同的哈希值
- powershell - 如何设置 Open-XML-PowerTools