Angular directive to replace '404' image with default image
✓ Published0🌍 Public
MMattDionis
Last edited May 3, 2015
Created on May 3, 2015
This example shows an Angular directive that automatically replaces a broken image with a default fallback image. The `defaultImage` directive binds to the `error` event on an `<img>` element and swaps the `src` attribute to a specified fallback URL when the original image fails to load. The directive uses Angular’s `link` function to attach the event listener, and the sample HTML applies it via the `default-image` attribute alongside `ng-src`, referencing a fallback URL from Instagram’s anonymous user profile. The implementation relies solely on Angular’s directive API and native DOM events.
AI-generated description