View Queries with viewChild
Query child elements as signals.
Querying the View
Components often need a reference to an element or child component in their template. Modern Angular provides the signal-based viewChild() query function.
Declaring a viewChild
Call viewChild() with a template reference name or a component type. The result is a signal.
import { Component, viewChild, ElementRef } from "@angular/core";
@Component({
selector: "app-form",
template: "<input #box>"
})
export class FormComponent {
box = viewChild<ElementRef>("box");
}All lessons in this course
- Signal Inputs with input()
- Required and Transformed Inputs
- Outputs with output()
- View Queries with viewChild