Skip to main content

What does ngAfterViewChecked() do? When is it called?

In Angular, ngAfterViewChecked() is a lifecycle hook that is called after every check of the component's view and its child components.

Key points

  1. What it does:
  • Lets you react to changes in the DOM and child components after they are rendered.
  • Used to run logic that depends on the current state of the view after every change check.
  1. When it is called:
  • After ngAfterViewInit() - the first call happens right after the view is initialized.
  • Repeatedly, on every Angular change detection check, for example when data or events change.

Example:

ts
export class MyComponent implements AfterViewChecked { ngAfterViewChecked() { console.log('Component view and child components were checked'); } }

In other words, ngAfterViewChecked is a hook for tracking and reacting to changes in the component's view and its child elements on every Angular change detection cycle.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.