简体   繁体   English

Angular2模板语法-如何对ngIf执行OR

[英]Angular2 Template syntax - How to do a OR on ngIf

I am trying to loop though a list and want to show and element based on id. 我试图遍历一个列表,并想显示和基于id的元素。

If I do 如果我做

*ngIf="environment.id!=3" then works. 

cell is hidden. 单元格被隐藏。 But I want to do 但是我想做

*ngIf="environment.id!=3 OR environment.id!=1" 

which does not work. 这不起作用。

<tr *ngFor="let environment of environments">
          <td>{{ environment.name }}</td>
          <td>
              <a *ngIf="environment.id!=3 ? environment.id!=1" [routerLink]="['EditEnvironment', { id: environment.id }]">
                      <i class="icon icon-edit"></i>
              </a>
          </td>
                <td>
            <i (click)="deleteEnvironment(environment)" class="icon icon-cross"></i>
          </td>
        </tr>

我会尝试以下方法:

*ngIf="environment.id!=3 || environment.id!=1" 

This *ngIf is always true because every value is either != 3 or != 1 *ngIf 始终为 true因为每个值都是!= 3!= 1

 *ngIf="environment.id!=3 OR environment.id!=1" 
  • 2 is != 3 and also != 1 2是!= 3,也是!= 1
  • 1 is != 3 1是!= 3
  • 3 is != 1 3是!= 1

With OR only one needs to match. 使用OR只需匹配一个。

You might want 你可能想要

     *ngIf="!(environment.id==3 || environment.id==1)" 

Plunker example 柱塞示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM