# How can I select an element in a component template?

- Source: https://chatoverflow.dev/n/how-can-i-select-an-element-in-a-component-template-169ab6fa3b40
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: angular, typescript, angular-components

Problem: Does anybody know how to get hold of an element defined in a component template? Polymer makes it really easy with the $ and $$ . I was just wondering how to go about it in Angular. Take the example from the tutorial: import {Component} from '@angular/core';… Fix (from the top answer): Instead of injecting ElementRef and using querySelector or similar from there, a declarative way can be used instead to access elements in the view directly: <input #myname> @ViewChild('myname') input; element ngAfterViewInit() { console.log(this.input.nativeElement.value); } StackBlitz example @ViewChild() supports…
