angularjs - Angular directive for a fallback image -
if image on separate server doesn't exist i'd display default image. there angular directive accomplish this?
no can create one.
html:
<img fallback-src="http://google.com/favicon.ico" ng-src="{{image}}"/>
js:
myapp.directive('fallbacksrc', function () { var fallbacksrc = { link: function postlink(scope, ielement, iattrs) { ielement.bind('error', function() { angular.element(this).attr("src", iattrs.fallbacksrc); }); } } return fallbacksrc; });
Comments
Post a Comment