I'm looking for a clean way to detect when all child directives of a given
type have been linked. I want the parent directive to be generic so it
should work regardless of whether the child elements use ng-repeat or not.
Note that ng-repeat changes the linking order.
Example 1: The parent post-link function will be executed after all the
child elements have been linked, so I can simply track each child as it is
linked then process them during parent post-link.
<parent>
<child></child>
<child></child>
<child></child>
</parent>
Example 2: ng-repeat changes the linking order. In this case, the parent
post-link will have already completed before attempting to link the
children. Therefore, I can't use the parent post-link function to determine
when all children have been linked, but I can add a check for $scope.$last
on each child.
<parent>
<child ng-repeat="c in children"></child>
</parent>
The problem I'm having is coming up with a nice, clean solution to handle
both cases as it seems wrong for a parent to have to check whether the
children use ng-repeat or not. Currently what I'm doing is inserting a
dummy child into the template to hold the transcluded children using
ng-repeat.
<child ng-transclude ng-repeat="dummy in [0]"></child>
That forces example 1 to act like example 2 and always generate a
$scope.$last. It appears to work but has a definite smell about it.
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.