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?
Asked
Active
Viewed 3,148 times
2
-
Hard to tell without seeing what you're doing. Can you reproduce in a Plunker? – Günter Zöchbauer Feb 28 '17 at 10:04
-
please post some code which having error – Pardeep Jain Feb 28 '17 at 10:05
-
I can't post so many lines of code and there is no error. I just have this hook called twice causing a view side effect. – koninos Feb 28 '17 at 10:08
2 Answers
1
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

Community
- 1
- 1

Jörg Frantzen
- 170
- 1
- 6
0
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.

greg
- 1,673
- 1
- 17
- 30