I'm trying write a directive
to remove an img
element if ng-src
results in 404
. The directive works, but the broken img
appears for a second and then being removed. I'm trying to remove the element before it is rendered in the GUI.
TS:
import { IDirective } from "angular";
/* @ngInject */
export function imgSrcErr($http): ng.IDirective {
return {
link: (scope, element, attrs) => {
element.bind("error", () => {
element.parent().remove();
console.log("error");
});
}
};
}
Html:
<img img-src-err ng-src="{{$ctrl.model.pictureUrl}}"/>