So I wrote a simple directive that intercepts 404 for the images and fallback to another image when the first one fails to load.
Works quite well but I'm having problems with some urls that returns a 404 status code but still return an image in the body (Google+ for instance).
If you want to have a look the sample of code is here https://jsfiddle.net/4cjb5srh/1/
angular.module('test', [])
.directive('imgMissing', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('error', function() {
console.log('image missing');
});
}
}
}]);
In this example, the Google+ image doesn't trigger the error but the linkedin image does. I tried to use jquery .error() instead of jqlite bind('error') but didn't solve the issue.
Edit: JimTheDev pointed out that it might be the same question as if a ngSrc path resolves to a 404, is there a way to fallback to a default?. Both my and this other question are to fall back on 404 however this one is specific to the case where a 404 is returned but error is not triggered (when the response-type is specified as explained below by kwan245).