Created
August 4, 2015 06:10
-
-
Save renesansz/1d8f15520ff0cf841a01 to your computer and use it in GitHub Desktop.
Image Fallback Source for Angular JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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