-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadImage.js
More file actions
32 lines (29 loc) · 1.03 KB
/
loadImage.js
File metadata and controls
32 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
angular.module('fnloadImage').directive('loadImage', function($filter){
return {
restrict: 'EA',
template: '<div class="load-image-wrap">'+
'<img src="{{imgSrc}}" ng-hide="loading" />'+
'<p ng-show="loading">Loading...</p></div>',
scope: {
imgSrc: '@', //path of the image path to load
fallbackSrc: '@' //path of the fallback image loacation
},
replace: true,
link: function(scope, el, attrs) {
scope.loading = true;
function stopLoading(){
scope.loading = false;
scope.$digest();
}
angular.element(el.children()[0]).bind("load" , function(event){
stopLoading();
});
angular.element(el.children()[0]).bind("error", function(){
stopLoading();
if(angular.isString(scope.fallbackSrc)){
el.children()[0].src = scope.fallbackSrc;
}
});
}
}
});