I am trying to find a way to detect when an element is finally appended to DOM? Is there any directive that I can create and attach to that element so it will detect the moment of appending? By creating elements I mean ng-repeat, and onload and $last do not work for me.
Asked
Active
Viewed 339 times
0
-
I'm very curious why you need to do this. My second thought is you can usually find some sort of event fired by the browser when things like this happen so I would search there. – shaunhusain Jul 12 '13 at 18:58
-
well I am creating the elements using angular and then I need access to those elements right after I create them so I can perform a manipulation on them, but they are not visible yet, since they are deep inside the template. $timeout works but I am looking for a better solution. – Georgi Angelov Jul 12 '13 at 19:02
-
Why not just bind things to the view so the updates are made automatically when things in the model change? I know this doesn't cover all scenarios but I feel like people try to shoehorn other solutions when this would work fine, unfortunately I don't have a direct answer for you though either, hopefully someone who has tried this will chime in. Is this a scenario where a class change won't handle it (you need info from the browser about computed metrics?) – shaunhusain Jul 12 '13 at 19:04
-
2You can't always determine when the DOM is updated. I suggest reading [Miško's comment](https://github.com/angular/angular.js/issues/734#issuecomment-3657272). – Mark Rajcok Jul 12 '13 at 19:35
-
Good read at the bottom there Igor also notes a couple of events that can one can listen for. – shaunhusain Jul 12 '13 at 19:49
-
1You could also attempt to deal with all the browsers different event systems too, it seems at least Mozilla and Chrome would allow this: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver?redirectlocale=en-US&redirectslug=DOM%2FMutationObserver But I would strongly consider if what you're doing in the way you're trying to do it is really correct. – shaunhusain Jul 12 '13 at 19:56
-
Well the thing is that I am not certain if what I am trying to do is going to be done in the correct way. That is why I am looking for different opinions on what the right way is... – Georgi Angelov Jul 14 '13 at 13:52