Issue
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?
Solution
No but you 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;
});
Answered By - Ketan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.