The author of this article on Creating Advanced Components demonstrates selecting an element by creating a directive first:
@Directive({
selector: '.tooltip-container'
})
export class TooltipContainerDirective {}
Then, the author uses this directive to select the element that contains the class .tooltip-container
as shown below:
@Component({
template: `
<div class="tooltip-container" [ngStyle]="{top: top}">
<ng-content></ng-content>
</div>
`,
styles: [...]
})
export class TooltipComponent implements OnInit {
top : string;
@ViewChild(TooltipContainerDirective, { read: ElementRef }) private tooltipContainer;
}
Is there a way in Angular to select the tooltipContainer
element by its class name without relying on the directive?