Skip to main content
InterviewHubPRO
Section Overview
Q191

Question 191 of 283

Part 8: Internationalization (i18n), Testing & DOM Directives (177 - 212)

67%
Angular Master (283 Qs)•Part 8: Internationalization (i18n), Testing & DOM Directives (177 - 212)

How do you select an element in component template?

mid LevelCode ExampleDirectivesComponentsTesting

You can control any DOM element via ElementRef by injecting it into your component's constructor. i.e, The component should have constructor with ElementRef parameter,

javascript
constructor(myElement: ElementRef) {
 el.nativeElement.style.backgroundColor = 'yellow';
}