简体   繁体   English

Angular6多个ngFor用于单行-如何在一个ngFor中传递两个值

[英]Angular6 multiple ngFor for single row - How to pass two values in one ngFor

In table head I have dynamic columns and search sorting functions. 在表头中,我具有动态列和搜索排序功能。 but for particular columns I need to disable sorting function. 但是对于特定的列,我需要禁用排序功能。 In table 在桌子上

<thead>
      <tr class="table-head">
        <th *ngFor="let colName of reportColHeader; let i = index">
          {{colName}}
          <i [class]="sortIcons[colName]" (click)="toggleSort(colName, i)"></i>
        </th>
      </tr>
    </thead>

In constructor I have passing values as array. 构造函数中,我将值作为数组传递。 Not from server its static only 不是仅来自服务器静态

this.reportColHeader = ['ID', 'LABEL 1', 'LABEL 2', 'More'];

so the result will be like below 因此结果将如下所示

<tr>
 <th>ID <i></i></th>
 <th>LABEL 1 <i></i></th>
 <th>LABEL 2 <i></i></th>
 <th>More <i></i></th>
</tr>

Here I want to disable 在这里我要禁用 (sorting function) from particular column. (排序功能)来自特定列。
Not only last column or nth column. 不仅最后一列或第n列。 My assumption is, is possible to have one more array like 我的假设是,可能再有一个数组

this.reportColHeaderOptions = ['true', 'true', 'false', 'false'];

by this values can show or hide the <i></i> 通过此值可以显示或隐藏<i></i>
So how can I pass this inside ngFor . 那么我如何在ngFor传递这个ngFor
Note: here I can't use index since the index will change. 注意:这里我不能使用索引,因为索引会改变。
but I can follow this.reportColHeader and this.reportColHeaderOpions in same order. 但我可以按照相同的顺序关注this.reportColHeaderthis.reportColHeaderOpions

Why can't you use index ? 为什么不能使用index You can do this : 你可以这样做 :

    <th *ngFor="let colName of reportColHeader; let i = index">
      {{colName}}
      <i *ngIf="reportColHeaderOpions[i]=='true'"></i>
    </th>

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

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