Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render {{ }} during ng-repeat?

consider following directive:

.directive('otherDirective', function(){
  return {
    link: function(scope, elem, attr){
      console.log(elem[0]);
      alert(elem[0]);
    }

  }

if I apply it into a ng-repeat tag, I can notice the {{item}} is not evaluated until the ng-repeat ends (when blocked by alert()). how can I have it rendered after each "loop"?

Because in real scenario, those items contain an image, and I would like to do callbacks after each image is loaded, but without the img url I can't bind the event.

here is the plunker

like image 557
Yichaoz Avatar asked Aug 11 '26 01:08

Yichaoz


1 Answers

Use $timeout to wait for ng-repeat to finish: Plunker

.directive('otherDirective',['$timeout', function($timeout){
  return {
    link: function(scope, elem, attr){
      $timeout(function () {
        console.log(elem[0]);
        alert(elem[0]);
      });
    }
  };
}]);
like image 54
Joy Avatar answered Aug 13 '26 12:08

Joy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!