Get component for children / children using viewContainerRef in Angular2

Inside a component, we can get child components using the following constructs:

@ViewChildren(MdVerTabLabelWrapper) _labelWrappers: QueryList<MdVerTabLabelWrapper>;
@ViewChildren(MdVerInkBar) _inkBar: QueryList<MdVerInkBar>;

However, if I have a viewContainerRef link, then how do I get the child component (s)?

Basically, what I'm trying to do is list the components, and I need to find the children of these components programmatically.

+4
source share
1 answer

The ViewContainerRef class has length and get (index) properties for accessing child elements. See the API here:

https://angular.io/docs/ts/latest/api/core/index/ViewContainerRef-class.html

, , viewContainerRef.get(childOfInterestIndex), for, - for(var index = 0; index < viewContenrRef.length; index++)

+2

Source: https://habr.com/ru/post/1651454/


All Articles