I have the following directive:
.directive("picSwitcher", ["$timeout", function($timeout){
return {
restrict: "A",
scope: {
pics: "=",
fadeTime: "@",
timeForPic:"@"
},
template: '<img ng-repeat="pic in pics" src="{{pic.url}}" style="display: none"/>',
link: function ($scope, element){
//some code...
$(element.find("img")[0]).css({display: "block"});
}
};
}])
my problem is, when my link function is invoked - ng repeat is yet to "compile" (what word should be used here instead of compiled?)
so I am trying to set css of undefined.. how can I force the link function to run after ng-repeat finished?!
for now I am solving this by replacing $(element.find("img")[0]).css({display: "block"});
with $timeout(function(){
$(element.find("img")[0]).css({display: "block"});}, 200);
but that feels 'hacky'
is there something I am missing to achieve my goal in an easier way? in general, what is the best way to manipulate ng-repeat dom element inside the link function of a custom directive?
Thanks, Jimmy.