首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Angular中使用Mat表中的NgFor

在Angular中使用Mat表中的NgFor
EN

Stack Overflow用户
提问于 2019-05-22 14:09:29
回答 1查看 2.5K关注 0票数 0

在我的代码中,我可以迭代no。表,但问题是列号。并且它的名称对于所有被迭代的表都是相同的。我怎么才能修复它?

代码语言:javascript
复制
    <div class="mat-table {{defaultView == 'table' ? 'mat-table-lg' : 'mat-table-sm'}}" data-automation-attribute="div-results">
       <mat-table #table *ngFor="let dataSource of dataSources let Ind = index" [dataSource]="dataSource" matSort>                  
          <ng-container *ngFor="let disCol of displayedColumnss let colIndex = index" matColumnDef="{{disCol}}">
            <mat-header-cell class="tableHeader" style="font-weight: bold" *matHeaderCellDef mat-sort-header>
              {{ columnNames[colIndex] }}  
             
            </mat-header-cell>     
            <mat-header-cell class="tableHeader" style="font-weight: bold" *matHeaderCellDef >
                <mat-cell *matRowDef ><input matInput placeholder="Item Code" >   </mat-cell>    
                <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
                <mat-cell *matCellDef> {{colIndex}}</mat-cell>
              </mat-header-cell>         
          
            <mat-cell *matCellDef="let element" style="text-align: right" contenteditable="true"
              ><label>{{element[disCol]}}</label>
              </mat-cell>
          </ng-container>
          <mat-header-row *matHeaderRowDef="displayedColumnss"></mat-header-row>
          <mat-row *matRowDef="let row; columns: displayedColumnss;">             
          </mat-row>
        </mat-table><br>
    
      </div>
EN

回答 1

Stack Overflow用户

发布于 2019-05-22 14:21:54

尝尝这个

代码语言:javascript
复制
ngFor="let item of items; let i = index" [attr.data-index]="i
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56250326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档