Skip to content

Instantly share code, notes, and snippets.

@jpotts18
Last active June 18, 2016 21:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpotts18/7161375 to your computer and use it in GitHub Desktop.
Save jpotts18/7161375 to your computer and use it in GitHub Desktop.
Angular Image Src fallback Directive
Directives.directive('fallbackSrc', function() {
return {
restrict: 'A',
link: function(scope, element, attrs){
if(_.isEmpty(attrs.ngSrc)){
element.attr('src', attrs.fallbackSrc);
}
element.bind('error', function(){
element.attr('src', attrs.fallbackSrc);
});
}
};
});
@IgorHorta
Copy link

This was usefull for me! thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment