Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does Angular trigger ngAfterContentChecked?

According to the docs the AfterContentChecked lifecycle hook is triggered:

after Angular checks the content projected into the component

What does "Angular checks" in the documentation mean, exactly?

like image 398
Raed Khalaf Avatar asked Jun 18 '17 10:06

Raed Khalaf


People also ask

What is ngAfterContentChecked in Angular?

A callback method that is invoked immediately after the default change detector has completed checking all of the directive's content.

When should I use Afterviewchecked?

When should you use ngAfterViewChecked? ngAfterViewChecked is useful when you want to call a lifecycle hook after all child components have been initialized and checked.

What is the frequency that Angular call the ngOnInit () method?

This method is called only once during the component lifecycle, after the first ngOnChanges call. ngOnInit() is still called even when ngOnChanges() is not, which is the case when there are no template-bound inputs. This is one of the most used lifecycle hooks in Angular.

What is the correct order of lifecycle hooks in Angular?

Angular calls lifecycle hook methods on directives and components as it creates, changes, and destroys them. A component has a lifecycle managed by Angular. Angular creates it, renders it, creates and renders its children, checks it when its data-bound properties change, and destroys it before removing it from the DOM.


1 Answers

AfterContentChecked, component-only hook, is called after Angular checks the content projected into the component (it's data-bound properties).

When does Angular check the projected content?

  • Initially, after the AfterContentInit hook finishes.
  • Every time the change detection is run (application state change).

What causes the application state change?

  • Events - click, submit, …
  • Ajax calls - fetching data from a remote server
  • Timers - setTimeout, setInterval

See also: Angular change detection explained.

like image 86
seidme Avatar answered Sep 20 '22 13:09

seidme