0Pricing
Angular Academy · Lesson

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

  1. Signal Inputs with input()
  2. Required and Transformed Inputs
  3. Outputs with output()
  4. View Queries with viewChild
← Back to Angular Academy