[英]Getting Child Component of tbody
我無法使用元素引用和查詢選擇器訪問Angular 2應用程序中的數據表行。
ngAfterViewInit(){
var e1 = this._elementRef.nativeElement.querySelector("tbody");
console.log(e1);
e1.draggable="true";
}
上面的代碼顯示了帶有tbody和子tr的數據。
但是,當我使用
ngAfterViewInit(){
var e1 = this._elementRef.nativeElement.querySelectorAll("tbody tr");
console.log(e1);
e1.draggable="true";
}
結果為空或空白數組。[]
querySelector
和querySelectorAll
之間有區別。
querySelector
對您querySelector
地方是因為它返回DOM(如您所說的返回了數據)。
但是使用querySelctorAll,您將獲得Node列表。 因此,嘗試遍歷該列表,您將獲得表行。
e1.forEach(tr => console.log(tr));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.