简体   繁体   中英

How often does code in an *ngIf condition in Angular 2+ fire?

I am curious about how *ngif works:

<img *ngif="isMediaMessage(message) === 'audio'" src="assets/img/audio1" />

1) When I put a console inside the isMediaMessage function, the console prints out indefinitely; I wonder why it does that. Is it because of the digest loop? dirty checking? I am reading up more on these.

2) Should I use less data binding if I want to reduce rendering time?

3) Would you guys say this article is up to date?

This might be related.

This is concerning to the digest loop/detection cycle and the watches on the page.

Every time there is a change in the page and the queue of dirty checking is running then the mechanism of detection is running will reevaluate the ngIf and your code/condition of ngIf will fire.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM