Home > Mobile >  angular check column in matCellDef loop
angular check column in matCellDef loop

Time:03-23

How do we check a column in an ng for loop in angular ? for example I dont wanna apply the logic below which is {{element[p.key] != null ? '$' : ''}} to column 1 or execept column 1

enter image description here

#html code

<table mat-table [dataSource]="bovDemos" >
                    <ng-container  *ngFor="let p of marketDemographicsTableLabel; last as l" matColumnDef="{{p.key}}">
                      <th mat-header-cell *matHeaderCellDef >{{p.label}}</th>
                      <ng-container >
                        <td  mat-cell *matCellDef="let element; index as i"
                        [ngClass]="{'border-none': i === bovDemos.length - 1}" >
                        {{element[p.key] != null ? '$' : ''}}{{(element[p.key]) ? (element[p.key] | number): '-'}}</td>
                      </ng-container>
                    </ng-container>
                    <tr mat-header-row *matHeaderRowDef="tableMarketDemographicsHeaders"></tr>
                    <tr mat-row *matRowDef="let row; columns: tableMarketDemographicsHeaders;" >
                    </tr>
                  </table>

CodePudding user response:

You have set "index as i", so you can use "i" to detect first td.

<span *ngIf="i===0">
   ..this is first column
 </span>
<span *ngIf="i!==0">
{{element[p.key] != null ? '$' : ''}}{{(element[p.key]) ? (element[p.key] | number): '-'}}
</span>
  • Related