2018-02-10 15:18:01 +00:00
|
|
|
import ngModule from '../module';
|
2018-05-22 09:44:24 +00:00
|
|
|
import noImage from './no-image.png';
|
2018-01-25 12:37:27 +00:00
|
|
|
|
2018-05-22 09:44:24 +00:00
|
|
|
/**
|
|
|
|
* Sets a default image when there is an error loading
|
|
|
|
* the original image.
|
|
|
|
*
|
|
|
|
* @return {Object} The directive
|
|
|
|
*/
|
|
|
|
export default function onErrorSrc() {
|
2018-01-25 12:37:27 +00:00
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link: (scope, element, attrs) => {
|
2018-05-22 09:44:24 +00:00
|
|
|
let imgError = noImage;
|
2018-01-25 12:37:27 +00:00
|
|
|
element.bind('error', function() {
|
2018-05-22 09:44:24 +00:00
|
|
|
if (attrs.src != imgError)
|
2018-01-25 12:37:27 +00:00
|
|
|
attrs.$set('src', imgError);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2018-02-10 15:18:01 +00:00
|
|
|
ngModule.directive('onErrorSrc', onErrorSrc);
|