【问题标题】:ngIf array contains indexngIf 数组包含索引
【发布时间】:2018-02-12 14:23:08
【问题描述】:

我有以下代码:

  <li *ngFor="let item of serviceList; let i = index;">
       <button *ngIf="currentTools contains i" (click)="processService(item)">
       Run Service</button>
  </li>

Angular 2 中有什么方法可以检查数组是否包含我的项目的索引?

我基本上只想显示索引号在数组(currentTools)中的项目,该数组在不同的进程中动态修改。

【问题讨论】:

    标签: arrays angular angular-ng-if


    【解决方案1】:
    <li *ngFor="let item of serviceList; let i = index;">
      <button *ngIf="currentTools.indexOf(i)>-1" (click)="processService(item)">
        Run Service
      </button>
    </li>
    

    试试这个

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-06
      • 2011-05-27
      • 1970-01-01
      • 2018-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多