Last active
August 29, 2015 14:20
-
-
Save MattDionis/d91f367150b32453295b to your computer and use it in GitHub Desktop.
Angular directive to replace '404' image with default image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular | |
.module('app') | |
.directive('defaultImage', defaultImage); | |
function defaultImage() { | |
var directive = { | |
link: link, | |
restrict: 'A' | |
}; | |
return directive; | |
function link(scope, element, attrs) { | |
element.bind('error', function() { | |
element.attr('src', attrs.defaultImage); | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img ng-src="{{photo.profile}}" default-image="https://instagramimages-a.akamaihd.net/profiles/anonymousUser.jpg"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment