Angular directive for a fallback image

前端 未结 4 914
走了就别回头了
走了就别回头了 2020-11-30 21:13

If an image on a separate server doesn\'t exist I\'d like to display a default image. Is there an angular directive to accomplish this?

4条回答
  •  悲哀的现实
    2020-11-30 21:46

    I wrote my own fallback lib.

    A pretty simple and straightforward angular fallback image lib:

    https://github.com/alvarojoao/angular-image-fallback

    Utility to work with loading images and handling image error, has image-holder to handle errors in image loading and image-loading for images loading placeholders

    http://alvarojoao.github.io/angular-image-fallback

    Usage

    Just add the image attribute to your tags

    
    

    Make sure you don't use ng-src as your image src attribute.

    Advanced options

    with custom fallback and loading placeholders:

    
    

    Example:

    https://jsfiddle.net/alvarojoao/4wec4gsq/embedded/result/

提交回复
热议问题