salix/front/core/directives/on-error-src.js

23 lines
575 B
JavaScript

import ngModule from '../module';
import noImage from './no-image-dark.png';
/**
* Sets a default image when there is an error loading
* the original image.
*
* @return {Object} The directive
*/
export default function onErrorSrc() {
return {
restrict: 'A',
link: (scope, element, attrs) => {
let imgError = noImage;
element.bind('error', function() {
if (attrs.src != imgError)
attrs.$set('src', imgError);
});
}
};
}
ngModule.directive('onErrorSrc', onErrorSrc);