0

I was working on a app where I encountered a peculiar case. For simplicity I have created a sample app and tested this although the behaviour was same.

Sample app:

In the parent component(my-app) I have the same child component with *ngIf and without it. The condition in *ngIf is mentioned upfront but despite it as you can see the method [check()] associated with it is executed last.

enter image description here

Excepted: The Method Check() should execute first and then Check2()

Apoorva Chikara
  • 8,277
  • 3
  • 20
  • 35
Jason
  • 325
  • 2
  • 4
  • 12
  • and the problem is? – Dalorzo Nov 12 '21 at 05:06
  • The check() is executed after check2() – Jason Nov 12 '21 at 05:08
  • yes for obvious reasons. That is how it should work – Dalorzo Nov 12 '21 at 05:11
  • @Dalorzo: elaborate? – Jason Nov 12 '21 at 05:14
  • structural directives create embedded view, which is somewhat a child of a current view and because of that will be executed later – Andrei Nov 12 '21 at 07:13
  • @Andrei IMO directives don't have a view, though when dig deeper it found out the structural directive use a function called _updateview() as mentioned in this link https://itnext.io/the-in-and-outs-of-angular-ngif-2bc3ca7bc0fe – Jason Nov 12 '21 at 07:38
  • do you see `createEmbeddedView` even in the article that you've mentioned? that is what I meant – Andrei Nov 12 '21 at 16:22
  • so it's executed later but remembered the place to render. isn't there a legit way to customize it or delay subsequent executions until it itself resolves. @Andrei – Jason Nov 12 '21 at 17:09

0 Answers0