首页 > 解决方案 > 如何在角度的ngIf中使用OR条件?

问题描述

假设我在 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)如果条件中的任何一个必须进入该部分,我想要条件。

标签: angularangular6

解决方案


ngIf 的工作方式与普通 If 条件的工作方式几乎相同。下面是一个例子。

<div class="form-group col-md-4" *ngIf="!condition1 || condition2">

推荐阅读