Skip to main content

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

In Angular, ngAfterContentChecked() is a lifecycle hook that is called after every check of the projected content in the component.

Key points

  1. What it does:
  • Lets you react to changes in content inserted through <ng-content>.
  • Used to run logic that depends on the state of the projected content.
  1. When it is called:
  • After ngAfterContentInit() - the first call happens after the content is first projected.
  • Repeatedly, every time Angular performs a change check on the component and its projected content.

Example:

ts
export class ChildComponent implements AfterContentChecked { ngAfterContentChecked() { console.log('Projected content was checked'); } }

In other words, ngAfterContentChecked is a hook that lets you track and react to changes in the projected content 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.