我正在努力开始学习角度发展。在回顾了文档之后,仍然存在一些问题。我如何最好地写一个 ng-if与多个参数对应
ng-if
if( a && b)或 if( a || b )
if( a && b)
if( a || b )
It is possible.
<span ng-if="checked && checked2"> I'm removed when the checkbox is unchecked. </span>
http://plnkr.co/edit/UKNoaaJX5KG3J7AswhLV?p=preview
Yes, it's possible. for example checkout:
<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>
For people looking to do if statements with multiple 'or' values.
<div ng-if="::(a || b || c || d || e || f)"><div>
Just to clarify, be aware bracket placement is important!
These can be added to any HTML tags... span, div, table, p, tr, td etc.
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
It's best practice not to do calculations directly within ngIfs, so assign the variables within your component, and do any logic there.
boolean check1 = Your conditional check here... ...