0

I have nested ng-repeat constructions inside my directive like this:

<calendar>
    <div class="calendar-row" ng-repeat="calendarRow in calendarRows">
       <calendar-day ng-repeat="calendarDay in calendarRow.days" />
    </div>
</calendar>

I need to execute a function after everything will be rendered. I will achieve this if I wrap my function is inside in 4 nested $timeout calls:

$timeout(function() {
    $timeout(function() {
        $timeout(function() {
            $timeout(function() {
                myFunc();
            });
        });
    });
});

It looks for me like a hack. Is it possible to reduce $timeout calls? I don't understand why 4 calls are needed in my case. Or is it more elegant way to implement it?

Nikolai Khe
  • 48
  • 1
  • 9
  • Possible duplicate of https://stackoverflow.com/questions/13471129/ng-repeat-finish-event – Kyle Krzeski Jun 16 '17 at 18:29
  • 1
    Also, wrapping your function in 4 $timeout calls is never the right answer – Kyle Krzeski Jun 16 '17 at 18:30
  • What are you trying to accomplish by waiting until the ng-repeat has finished rendering? – Kyle Krzeski Jun 16 '17 at 18:36
  • @WilliamHampshire, I know that 4 $timeout nested calls isn't a right answer, that's why I posted my question here, otherwise I wouldn't care. After rendering I have to check if scrolls are visible and set height of rows with class "calendar-row" to another column with rows which one is fixed. – Nikolai Khe Jun 16 '17 at 20:03

1 Answers1

0

One solution would be this:

<calendar>
    <div class="calendar-row" ng-repeat="calendarRow in calendarRows">
       <calendar-day ng-init="$last && myFunc()" ng-repeat="calendarDay in calendarRow.days" />
    </div>
</calendar>
Kyle Krzeski
  • 6,183
  • 6
  • 41
  • 52
  • thanks for your answer but I have already tried this solution and it didn't help. I used `ng-init="$last && $parent.$last && myFunc()"` but still I had to use `$timeout` inside `myFunc()` because `calendar-day` directives weren't fully rendered. – Nikolai Khe Jun 16 '17 at 20:08