ng-fallback-src
v1.0.2
Published
Fallback image src if you need it
Downloads
35
Readme
ng-fallback-src
replace 404s with some default asset, for better [empty] states.
Install
npm install --save ng-fallback-src
bower install --save ng-fallback-src
Example Usage
This was originally meant for img
tags only, but theoretically it could work for any element with a src
tag. This theory is untested so use at your own risk.
<img ng-src="{{someFlakyVar}}" fallback-src="{{someReliableUrl}}" />
Note: if someFlakyVar
can be falsy, you'll need to account for it separately, e.g.
<img ng-src="{{someFlakyVar || someReliableUrl}}"
fallback-src="{{someReliableUrl}}" />
since most browsers won't actually fire the error event if the src
is empty.
Contributing
The most obvious things right now are
- [ ] tests
- [ ] adding files so this can be published to other package managers.
Create your feature branch:
git checkout -b my-new-feature
Commit your changes:
git commit -am 'Add some feature'
Push to the branch:
git push origin my-new-feature
Create a new Pull Request
Credits
- @concertcoder [Chris Gosselin]: version
0.x
and helping correct a potential memory leak - @nexus-uw [Simon Ramsay]: pointing out that @concertcoder wrote this once upon a time