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.
Loading...
Related Quiz
- What is the primary benefit of using lazy loading in Angular applications?
- In Angular's Reactive Forms, the ______ is a service that provides convenient methods to construct form controls.
- If you need to clear all views from a ViewContainerRef, you would use the ______ method.
- What's the primary difference between the switchMap and mergeMap operators?
- You are building a dynamic form where users can add or remove input fields. Which feature or approach in Angular would be best suited for this requirement?