directive with ng-repeat and DOM manipulation after rendering

418 views
Skip to first unread message

Anton Trapp

unread,
Sep 30, 2014, 9:48:20 AM9/30/14
to ang...@googlegroups.com
Hi!

I am building a hidden list in a directive like that (simplified, tried to do it with transclude, but the transcluded stuff never works for me *lol*, so everything in the directive now):

<ul ng-repeat="elem in whatever">
 
<li>{{elem.something}}</li>

when the whole list has been rendered into the DOM I need to call a JavaScript function (3rd party). How can I get this DOM rendered event? Inside the link function I can watch the scope, but when the scope for the ng-repeat is changing the DOM has not even started to be rendered. So what I would need is something like (pseudo-code):

/* called when the whole rendering stuff is finished (including the ng-repeat has created the li items) */
whenRendered
: function() {
 
ExternalSericeCall();
}

in the directive declaration.

Thank you very much in advance!

Kind regards,
Anton

Anton Trapp

unread,
Sep 30, 2014, 10:30:12 AM9/30/14
to ang...@googlegroups.com
One "solution" I found: I created a small directive that sets a parent-scope variable on scope.$last and added it to the ng-repeat. When it is called the last time (scope.$last) is called the watch (defined in the link function of the directive above) is triggered and I can call the external JS. However this solution seems a little roundabout...

Joberto Diniz

unread,
Oct 3, 2014, 11:38:29 AM10/3/14
to ang...@googlegroups.com
Yeah.. we did the same when we need something similar.

Tony pee

unread,
Oct 3, 2014, 1:12:40 PM10/3/14
to ang...@googlegroups.com
there is also :  $evalAsync which i used successfully  - code on my other laptop. 

It is discussed here a little too:




--
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 angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
Tony Polinelli

Anton Trapp

unread,
Oct 4, 2014, 1:30:41 AM10/4/14
to ang...@googlegroups.com
Great! Tnx!
Reply all
Reply to author
Forward
0 new messages