且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当IMG在角7中URL的Asest文件夹中不可用时如何处理错误404

更新时间: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
  }
}