angular img标签使用err-src

在directive中定义组件,在ng-src错误时,调用err-src.

app.directive('errSrc',function() {

  return {

    link: function(scope, element, attrs) {

      if(attrs.src='undefined'){

        attrs.$set('src', attrs.errSrc);

      }

      element.bind('error', function() {

      if (attrs.src != attrs.errSrc) {

        attrs.$set('src', attrs.errSrc);

      }

    });

  }

}

});