![](/img/trans.png)
[英]Angular2: How to get a reference to a ViewChild in a child component
[英]In Angular, with ViewChild/ ViewChildren, how do I get the child of a child?
@ViewChildren(Subcomponent) sComp;
將使我得到當前組件的子組件子代,但我想獲取作為子組件子代的元素的值。 我怎么做?
在Subcomponent
您可以定義一個方法來返回其子級:
@ViewChildren(ChildA) childAOfSubcomponent;
getChildA() {
return this.childAOfSubcomponent;
}
現在在當前組件中使用:
this.sComp.getChildA(); // thi will return child of SubComponent
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.