Angular 如何访问div´的nativeElement;孩子们
我得到了一个家长divs的孩子,我通过这些孩子循环。我需要访问每个孩子的nativeElementAngular 如何访问div´的nativeElement;孩子们,angular,Angular,我得到了一个家长divs的孩子,我通过这些孩子循环。我需要访问每个孩子的nativeElement let children = Array.from(this.myParentDiv.nativeElement.children); for (let i = 0; i < children.length; i++) { console.log(children[i]); // Prints <div.... console.log(children[i].native
let children = Array.from(this.myParentDiv.nativeElement.children);
for (let i = 0; i < children.length; i++) {
console.log(children[i]); // Prints <div....
console.log(children[i].nativeElement); // Prints undefined
}
let children=Array.from(this.myParentDiv.nativeElement.children);
for(设i=0;i console.log(children[i]);//Printschildren[i]
是本机元素,它本身没有在dom中指定属性nativeElement
而nativeElement
是angular用来访问本机元素的属性,而不管平台(移动设备、浏览器等)children[i]
是本机元素本身,dom中没有指定属性nativeElement
而nativeElement
是angular用来访问本机元素的属性,无论平台(手机、浏览器等)如何。没有意识到我可以直接在子对象上调用属性[I]没有意识到我可以直接在子对象上调用属性[I]