Imagine you're building a custom tooltip directive in Angular. To ensure that the tooltip is positioned relative to the element it's attached to, you need to gain access to the host element. How would you achieve this?

  • ElementRef and Renderer2
  • Renderer2 and @ViewChild
  • ViewChild and ElementRef
  • ViewChild and Renderer2
To gain access to the host element when building a custom directive, you would typically use ElementRef and Renderer2. ElementRef allows you to access the host element directly, while Renderer2 provides a safe way to interact with the DOM. Using ViewChild can give you access to child components, not the host element. The combination of Renderer2 and ViewChild is not a common approach for this scenario.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *