ViewChild 裝飾器用於獲取模板視圖中的元素或直接調用其組件中的方法。它支持 Type 類型或 string 類型的選擇器,同時支持設置 read 查詢條件,以獲取不同類型的實例。
ViewChildren 裝飾器是用來從模板視圖中獲取匹配的多個元素,返回的結果是一個 QueryList 集合。
static:true 用於頁面初始化時就顯示的數據,可以結合ngAfterViewInit使用
static:false 用於頁面動態加載模板
@ViewChildren(ChildComponent,{static:true}) child @ViewChildren(ChildrenComponent) children:QueryList<ChildrenComponent>