Reputation: 1
I am building a website on rails using haml and angularJs.The images are loading from server. I want a placeholder image to be displayed if the image is not loading or its taking too much time. Thank you in advance!
Upvotes: 0
Views: 1588
Reputation: 934
So you will add a directive, which will get the original-src attribute and will replace the placeholder. As you can see it binds on the load event. Hope it helps.
Angular js:
app.directive('original', function() {
return {
restrict: 'A',
scope: { original-src: '@' },
link: function(scope, element, attrs) {
element.bind('load', function() {
element.attr('src', scope.original-src);
});
}
};
});
your html
<img original-src="original.jpg" src="placeholder.jpg" />
Upvotes: 2