Angular 2 - Check if image url is valid or broken

后端 未结 9 1992
感情败类
感情败类 2020-11-29 19:31

I am fetching a large number of image URLs from an API and display them in a angular 2 web application. Some of the URLs are broken and i want to replace them with a default

9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 20:06

    You can use onError event this way to handle invalid url or broken url.

    • https://plnkr.co/edit/fD8zxd?p=preview
  •  
    

    This way you can directly assign img path to src with onError event

提交回复
热议问题