koninos
koninos

Reputation: 5357

Why ngAfterContentInit hook is called twice?

According to docs ngAfterContentInit is called only once after the first NgDoCheck, but in my case is executed twice and I can't find the reason why this is happening. Any ideas about why this hook could be executed twice or any known side effects that can cause that?

Upvotes: 2

Views: 3969

Answers (2)

greg
greg

Reputation: 1873

If your component is instantiated twice, ngAfterContentInit will get called twice. For instance... a custom editor...

hard to say w/o seeing anything.
I had this 'problem' then realized why. I proved it by logging an instance specific variable.

Upvotes: 1

Jörg Frantzen
Jörg Frantzen

Reputation: 190

I get the same problem once in a while and it is usually caused by faulty code in the template. Can be hard to track down if it wasn't caused by the last thing you just changed.

This question is about ngOnInit: why ngOnInit called twice?, but I believe the problem is the same. Also see https://github.com/angular/angular/issues/6782

Upvotes: 1

Related Questions