Antoine Grenard
Antoine Grenard

Reputation: 1892

Angular ngAfterContentInit : what content are we talking about

I am trying to understand in details the lifecycle hook of Angular and I am struggling understanding ngAfterContentInit.

A callback method that is invoked immediately after Angular has completed initialization of all of the directive's content. It is invoked only once when the directive is instantiated.

What directive "content" are we talking about exactly ? Can someone explain me and provide me some examples ?

Upvotes: 0

Views: 848

Answers (1)

Jacopo Sciampi
Jacopo Sciampi

Reputation: 3433

The afterContentInit function gets called when the external component content has been initialized (Careful, initialized! Not rendered).

As the doc reports :

The AfterContent sample explores the AfterContentInit() and AfterContentChecked() hooks that Angular calls after Angular projects external content into the component.

After firing the AfterContentInit() Angular will fire another callback: AfterContentChecked(). This life-cycle is being fired after Angular has finished checking all the component's reference stuff (Input, Output, DI, and so on).

Upvotes: 2

Related Questions