mic*_*ael 23
注入元素本身:
constructor(private elRef: ElementRef){}
Run Code Online (Sandbox Code Playgroud)
访问本机元素父级:
ngOnInit() {
console.log(this.elRef.nativeElement.parentElement);
}
Run Code Online (Sandbox Code Playgroud)
您可以通过查找this.elRef.closest与该父元素匹配的一些选择器来访问最近的父 DOM 元素
constructor(private elRef: ElementRef){}
ngOnInit() {
const parentElement = this.elRef.closest('.parent-element-class')
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21250 次 |
| 最近记录: |