Last active
December 10, 2015 17:15
-
-
Save iambigd/d8de76fe082e07e9801e to your computer and use it in GitHub Desktop.
Angular ngSrc image not found directive
This file contains 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('errSrc', function() { | |
return { | |
link: function(scope, element, attrs) { | |
scope.$watch(function() { | |
return attrs['ngSrc']; | |
}, function (value) { | |
if (!value) { | |
element.attr('src', attrs.errSrc); | |
} | |
}); | |
element.bind('error', function() { | |
element.attr('src', attrs.errSrc); | |
}); | |
} | |
} | |
}) |
This file contains 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
<img ng-src="{{getADImageURL(ad)}}" err-src="{{notfound}}" /> |
This file contains 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
angular.module('myApp.controllers').controller('ADCtrl', ['$rootScope', '$scope', '$log', 'API_EVENTS', 'ServerConfig', 'AlertService', '$location', 'blockUI', 'ADService', '$sce', 'dialogs', '$filter', | |
function($rootScope, $scope, $log, API_EVENTS, ServerConfig, AlertService, $location, blockUI, ADService, $sce, dialogs, $filter) { | |
$log.log('load ad page'); | |
var notfoundImg = ServerConfig.endpoint + 'app/assets/images/404_img.png'; | |
// alert(notfoundImg); | |
$scope.notfound = notfoundImg; | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment