Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular detect if view is finished

I currently have a few ng-repeats in my view for building an agenda. Whenever I have a ng-repeat I can include a directive checking if the ng-repeat is done to trigger a method. Works perfect...

The problem is, I have like 5 ng-repeats, I don't want to include the directive for all 5 ng-repeats and check in the method if all 5 have called the method... I just want a way to detect if all my ng-repeats (and other angular stuff) is finished building the view so for example I can put appointments in the agenda via JQuery. Because ofcourse, putting appointments in the agenda (divs) before the agenda (divs) have been created won't work.

Thanks in advance!

UPDATE:

I'm using a REST backend to get the appointments from. So i can't just retrieve the appointments and try to show them in the agenda because the view might not be finished generating (using the ng-repeats)....

So I need something that is triggerd ones the view is done generating (ALL ng-repeats must be done) so i can start placing the appointments.

like image 399
Bas Van Den Heuvel Avatar asked Sep 26 '26 12:09

Bas Van Den Heuvel


1 Answers

You should use $viewContentLoaded rather than any directive as this fires after everything in the view loaded. Documentation : https://docs.angularjs.org/api/ngRoute/directive/ngView

Code Example : $scope.$on('$viewContentLoaded', function(event) { // Your Code Goes Here }); Note that this will only work if you are using ng-view from routing.

like image 171
Moe Shaaban Avatar answered Sep 29 '26 02:09

Moe Shaaban