Angular2: Show placeholder image if img src is not valid

后端 未结 8 1762
迷失自我
迷失自我 2020-12-12 12:55

Goal: Load an image with a dynamic source. If no image is found, then load a placeholder image instead.

This should demonstrate what I\'m trying to

8条回答
  •  春和景丽
    2020-12-12 13:10

    
    

    And somewhere in your component class:

    setDefaultPic() {
      this.pic = "assets/images/my-image.png";
    }
    

提交回复
热议问题