Angular2: Show placeholder image if img src is not valid

后端 未结 8 1761
迷失自我
迷失自我 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:30

    ...
    
    getImage():string{  //I don't know how would you handle your situation here. But you can think of it.
    
      if (this.validImage) // I don't know how would you manage validImage here.
      {
         return this.validImagePath;
      }
    
       return this.placeholderImagePath;
    }
    

提交回复
热议问题