3
我想知道,如果我們可以綁定或使用angular2插補圖像標籤上的onError,angular2 onError的圖像結合
在app.component.ts:
imageUrl:string;
constructor() {
this.imageUrl = 'graphics/placeholder.gif';
}
在app.component .html:
<img class="img-responsive" [src]="'graphics/image-1.jpg'" onError="imageUrl"/>
下面的方法工作。
<img class="img-responsive" [src]="'graphics/image-1.jpg'" onError="this.src='graphics/placeholder.gif'"/>
但是,正如我們在應用程序使用許多圖像,我想使它成爲一個簡單的動態解決方案,我發現這個答案好,
Angular 2 - Check if image url is valid or broken
但由於某種原因沒有工作,我不知道我在做什麼錯在這裏