Hi,

I am new in angularjs. Trying to implement img lazy loading. I made a 
directive which is replace place holder img when real img load.

JS Code :: 

var imgPlaceHolders = [ "1.png","2.png", "3.png",.......,"10.png"];
$scope.getImgPlaceHolder = function() {
var index = Math
.floor((Math.random() * 10) + 1);
// alert("index :: " + index);
// alert($rootScope.imgPlaceHolders[index]);
return imgPlaceHolders[index];
}

Code is :-
HTML Code :: 
<img hires = "{{post.album[0].replace('/size/', '/300/')}}" 
ng-src="{{getImgPlaceHolder()}}">  


directive ::

var imageLazyLoaingDirectives = angular.module('imageLazyLoaingDirectives', 
[]);

imageLazyLoaingDirectives.directive('hires', function() {
return {
restrict : 'A',
scope : {
hires : '@'
},
link : function(scope, element, attrs) {
// alert("scope.hires :: " + scope.hires);
element.one('load', function() {
element.attr('src', scope.hires);
});
}
};
});

Plz any one tell me what I did wrong.

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to