如果两个条件之一为真,如何隐藏角度元素

All*_*n.A 11 html javascript typescript angular

如果条件之一为真,如何隐藏角度元素。

我尝试使用 *ngIf="productID ==category.Lane ||productID ==category.Val"。这不起作用。

 <label>ProductID</label>
      <ng-select
        appearance="outline"
        
        formControlName="productId"
        [clearable]="false"
        [searchable]="false"
        [(ngModel)]="productID"
        placeholder="Select an option"
      >
        <ng-option *ngFor="let product of products | orderBy: 'name'" value="{{ product.id }}">{{ product.name }}</ng-option>
      </ng-select>
      
      <div class="row" *ngIf="productID == category.Lane || productID == category.Val">
      <div class="col">
      <label>Promotion</label>
     </div>
Run Code Online (Sandbox Code Playgroud)

Jen*_* MS 10

否则,您可以使用隐藏属性而不是使用 *ngIf 条件

<div class="row" [hidden]="productID == category.Lane || productID == category.Val">
Run Code Online (Sandbox Code Playgroud)


小智 9

有了这个条件:

*ngIf="productID == category.Lane || productID == category.Val"
Run Code Online (Sandbox Code Playgroud)

您是说,如果第一个或第二个条件为真,则显示该元素。如果你想隐藏它,在这种情况下你应该使用相反的条件:

*ngIf="!(productID == category.Lane || productID == category.Val)"
Run Code Online (Sandbox Code Playgroud)