103

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

if( a && b)或者if( a || b )

4

4 回答 4

176

有可能的。

<span ng-if="checked && checked2">
  I'm removed when the checkbox is unchecked.
</span>

http://plnkr.co/edit/UKNoaaJX5KG3J7AswhLV?p=preview

于 2013-09-24T17:37:22.673 回答
15

只是为了澄清,请注意支架放置很重要!

这些可以添加到任何 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

2 +

*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...
...
于 2019-05-31T11:49:41.613 回答
9

对于希望使用多个“或”值的 if 语句的人。

<div ng-if="::(a || b || c || d || e || f)"><div>
于 2017-08-09T15:40:32.727 回答
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>
于 2017-04-17T08:31:33.440 回答