[英]How to use OR condition in ngIf in angular?
假设我在component.ts中有逻辑:
selectInput(event) {
let selected = event.target.value;
if (selected == "firm") {
this.isNameSelected = true;
} else if(selected == "consignment") {
this.isNameSelected = false;
this.labelForCP=true;
}
else{
this.tash=true;
this.isNameSelected = false;
this.labelForCP=false;
}
}
在我的HTML中我有:
<div class="form-group col-md-4" *ngIf="!isNameSelected">
我试图结合*ngIf="!isNameSelected || tash"
但我在控制台中收到错误 ,因为我无法应用这种方法。 我想要条件,如果条件中的任何一个为true(OR condition)
它必须进入该部分。
ngIf的工作方式与普通的If条件相同。 以下是一个例子。
<div class="form-group col-md-4" *ngIf="!condition1 || condition2">
你可以用
<div class="form-group col-md-4" *ngIf="!(isNameSelected===true || tash ===true)">
如果条件正常,一般应该可以正常工作
<div class="form-group col-md-4" *ngIf="isNameSelected === false || otherCondition === true">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.