1.首先编写自定义指令

angular.module('starter.directives', [])
//当图片找不到事显示替代图片
   .directive("errSrc", function() {
      return {
         link: function(scope, element, attrs) {
            element.bind("error", function() {
               if (attrs.src != attrs.errSrc) {
                  attrs.$set("src", attrs.errSrc);
               }
            });
         }
      }
   })

2.引用

<img class="icon" ng-src="{{userData._avatar}}" ng-click="loadImage()" >

 

相关文章:

  • 2021-12-31
  • 2021-12-23
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
相关资源
相似解决方案