onErrorSrc directive for images

This commit is contained in:
Daniel Herrero 2018-01-25 13:37:27 +01:00
parent e6bba9e20e
commit abed869052
2 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,17 @@
import {module} from '../module';
function onErrorSrc() {
return {
restrict: 'A',
link: (scope, element, attrs) => {
let imgError = '/static/images/no-image200x200.png';
element.bind('error', function() {
if (attrs.src != imgError) {
attrs.$set('src', imgError);
}
});
}
};
}
module.directive('onErrorSrc', onErrorSrc);

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB