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.
<myVideo>
<mySource ng-attr-src="smooth.ism"></mySource>
<mySource ng-attr-src="progressive.mp4></mySource>
</myVideo>--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/m77brXJBa0I/unsubscribe.
To unsubscribe from this group and all its topics, 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.
![]() | Marc Coupar Software Developer |