简体   繁体   English

Angular 2+中* ngIf条件中的代码多久会发生一次火灾?

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

I am curious about how *ngif works: 我很好奇* ngif是如何工作的:

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

1) When I put a console inside the isMediaMessage function, the console prints out indefinitely; 1)当我在isMediaMessage函数中放置一个控制台时,控制台会无限期地打印出来; 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? 2)如果我想减少渲染时间,我应该使用更少的数据绑定吗?

3) Would you guys say this article is up to date? 3)你们会说这篇文章是最新的吗?

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. 每次页面发生更改并且脏检查队列正在运行时,检测机制将运行,将重新评估ngIf,并且您的ngIf代码/条件将被触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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