How to access parent HTML element from component?
Inject the element itself:
constructor(private elRef: ElementRef){}
access the native elements parent:
ngOnInit() {
console.log(this.elRef.nativeElement.parentElement);
}
You can access closest parent DOM element by looking up with this.elRef.closest
and some selector that matches that parent
constructor(private elRef: ElementRef){}
ngOnInit() {
const parentElement = this.elRef.closest('.parent-element-class')
}