Reputation: 2305
For getting the child component reference we have option-
@ViewChild(ChildComponent)
childComp: ChildComponent;
I wonder what if I have same child component twice or more, how I can get all same type child component in different different variable. For instance, inside my parent template I have-
<div>
<child-selector></child-selector>
<child-selector></child-selector>
</div>
How I can get reference of both same type child component inside parent component? Any help would be highly appreciated
Upvotes: 0
Views: 775
Reputation: 12596
Using ViewChildren
@ViewChildren(ChildComponent)
childComps: QueryList<ChildComponent>;
*The children element which are located inside of its template of a component are called *view children *. On the other hand, **elements which are used between the opening and closing tags of the host element of a given component are called *content children **.
http://blog.mgechev.com/2016/01/23/angular2-viewchildren-contentchildren-difference-viewproviders/
Upvotes: 1