[英]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.