* ngIf中的angular 6变量或方法绑定 [英] angular 6 variable or method binding in *ngIf

查看:142
本文介绍了* ngIf中的angular 6变量或方法绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在模板* ngIf中绑定变量和方法之间是否有任何区别.

Is there any difference between binding a variable and binding a method in template *ngIf.

例如:

案例1:

<div *ngIf="myVar">ABC</div>

案例2:

<div *ngIf="myFunction()">ABC</div>

myFunction() : boolean {
   if (cond1 && cond2 && cond3) {
       return true;
   } else { 
       return false;
   }
}

对性能有影响吗?

我正在尝试使用2种情况,获取范围错误:超出最大调用堆栈数.

I am trying to use the 2 case, getting range Error: Maximum call stack exceeds.

对此有帮助吗?谢谢

推荐答案

是的

第一个不会有任何性能问题,因为您直接检查一个变量,而第二个则因为角度使用更改检测并且会触发多次

The first one wont have any performance issue since you are directly checking against a variable while the second one will have since angular uses change detection and it fires many times

这篇关于* ngIf中的angular 6变量或方法绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆