更新时间:2022-05-03 16:44:33
镜像有onerror
属性,对于ion是ionError
(参见docs),可以用来执行代码。
<img [src]="'assets/icons/'+list?.type+'.png'" (ionError)="handleError(i)">
在那里,您可以改为为您的图像设置替代的src
属性。
export class MyPage {
list: YourListType[];
handleError(index: number) {
this.list[index].type = 'alternative-image-name';
// note that in your template you concat that with the `assets/icon` path and the .png ending
}
}