Angular & Signals (283 Qs)•Part 6: Decorators, Dependency Injection & Tooling (124 - 150)
How do you select an element with in a component template?
You can use @ViewChild directive to access elements in the view directly. Let's take input element with a reference,
html
<input #uname>
and define view child directive and access it in ngAfterViewInit lifecycle hook
javascript
@ViewChild('uname') input;
ngAfterViewInit() {
console.log(this.input.nativeElement.value);
}