簡體   English   中英

在Angular中,如何使用ViewChild / ViewChildren來生孩子?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM