Function inside ngIf is called multiple times, after a single click event- Angular2_Typescript

后端 未结 1 1118
时光说笑
时光说笑 2020-12-19 09:38

Hello this is the first time I qm putting question on stackoverflow. I am developing an application in angular2: v2.1.0 (typescript- v2.0.10). I am using \"ng2-file-upload\

相关标签:
1条回答
  • 2020-12-19 10:44

    It's actually quite easy.

    When ever you define an ngIf , you put an expression inside it right ?

    That means every time there is an update inside that component , Angular needs to make sure that the expression inside the ngIf is evaluated. ( This is what you expect from Angular right ? other wise why would you use ngIf ?)

    So every time there is an update in the model , or rather , every time there is something that triggers the changeDetection, Angular evaluates that expression , which in your case is a function ( isUploaderEmpty ).

    Generally , events are one of the things that fire a changeDetection( it's more complicated than this ).

    So that's why :D.

    0 讨论(0)
提交回复
热议问题