Skip to content

Instantly share code, notes, and snippets.

@rjoydip-zz
Last active August 12, 2018 06:28
Show Gist options
  • Save rjoydip-zz/18f640c70b7adb431040d48a7973acd2 to your computer and use it in GitHub Desktop.
Save rjoydip-zz/18f640c70b7adb431040d48a7973acd2 to your computer and use it in GitHub Desktop.
app.directive('imageExists', ['$http', 'IMAGE',
function($http, IMAGE) {
return {
restrict: 'EA',
link: function(scope, elem, attrs, ctrl) {
$http({
method: "GET",
url: attrs.src || attrs.ngSrc
}).then(function mySuccess(response) {
return;
}, function myError(response) {
if (response.status === 404) {
scope.mainImage = IMAGE.BASE_IMAGE;
}
});
}
};
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment