Within component we can get child components using following constructs:
@ViewChildren(MdVerTabLabelWrapper) _labelWrappers: QueryList<MdVerTabLabelWrapper>;
@ViewChildren(MdVerInkBar) _inkBar: QueryList<MdVerInkBar>;
However if I have viewContainerRef reference then how do I get child component(s)?
Basically what I am trying to do is I have list of components and I need to find children of those components programmatically.
The ViewContainerRef class has length and get(index) properties for accessing children. See the API here:
https://angular.io/docs/ts/latest/api/core/index/ViewContainerRef-class.html
So to reference a specific child, you use viewContainerRef.get(childOfInterestIndex)
, and to work on all children you use a for loop, using something like for(var index = 0; index < viewContenrRef.length; index++)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With