sanjihan
sanjihan

Reputation: 6002

:host equivalent in component.ts

In component.css you can access <component> tag with :host selector. Is there a direct way to access it in component.ts file?

I am aware of using ViewChild and parentElement, is there a more direct way of getting host DOM element?

Upvotes: 1

Views: 43

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657248

You can inject it

class MyComponent {
  constructor(private elRef:ElementRef) {}

  ngAfterViewInit() {
    this.elRef.nativeElement...
  }
}

Upvotes: 2

Related Questions