angular elementref parent 1

angular elementref parent

// Inject the element itself:
constructor(private elRef: ElementRef){}

// access the native elements parent:
ngOnInit() {

Here is what the above code is Doing:
1. We’re importing the ElementRef class from the @angular/core package.
2. We’re injecting the ElementRef class into our component.
3. We’re accessing the nativeElement property of the injected ElementRef class.
4. We’re accessing the parentElement property of the nativeElement property.

Similar Posts