Skip to content

Instantly share code, notes, and snippets.

@renesansz
Created August 4, 2015 06:10
Show Gist options
  • Select an option

  • Save renesansz/1d8f15520ff0cf841a01 to your computer and use it in GitHub Desktop.

Select an option

Save renesansz/1d8f15520ff0cf841a01 to your computer and use it in GitHub Desktop.
Image Fallback Source for Angular JS
/**
* App Directive: fallback-src
* -----------------------------
* This directive is being used along with <img> to set the src to default if incase the remote image isn't found.
*
* Usage: <img fallback-src="your-path-here" ng-src="to-remote-path" />
*/
(function () {
'use strict';
angular.module('app.directives')
.directive('fallbackSrc', fallbackSrc);
/**
* Nav Tab Menu
*/
function fallbackSrc(NG_PATH) {
return {
link: function (scope, ele, attrs) {
ele.bind('error', function () {
// angular.element(this).attr('src', attrs.fallbackSrc);
attrs.$set('src', attrs.fallbackSrc);
});
}
};
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment