Angular ng-if =“”,带有多个参数


94

我正在尝试开始进行角度开发。在查阅了文档之后,一些问题仍然存在。我如何最好地写一个ng-if与多个参数对应的

if( a && b) 要么 if( a || b )

Answers:




3

是的,有可能。例如结帐:

<div class="singleMatch" ng-if="match.date | date:'ddMMyyyy' === main.date &&  match.team1.code === main.team1code && match.team2.code === main.team2code">
    //Do something here
    </div>

3

为了澄清起见,请注意支架的位置很重要!

这些可以添加到任何HTML标记中... span,div,table,p,tr,td等。

AngularJS

ng-if="check1 && !check2" -- AND NOT
ng-if="check1 || check2" -- OR
ng-if="(check1 || check2) && check3" -- AND/OR - Make sure to use brackets

Angular2 +

*ngIf="check1 && !check2" -- AND NOT
*ngIf="check1 || check2" -- OR
*ngIf="(check1 || check2) && check3" -- AND/OR - Make sure to use brackets

最佳实践是不要直接在ngIfs中进行计算,因此请在组件中分配变量,并在其中进行任何逻辑。

boolean check1 = Your conditional check here...
...
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.