[SOLVED] angular check column in matCellDef loop

Issue

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" class="mat-elevation-z0">
                    <ng-container  *ngFor="let p of marketDemographicsTableLabel; last as l" matColumnDef="{{p.key}}">
                      <th mat-header-cell *matHeaderCellDef class="fs-12px">{{p.label}}</th>
                      <ng-container >
                        <td  mat-cell *matCellDef="let element; index as i"
                        [ngClass]="{'border-none': i === bovDemos.length - 1}" class="fs-12px">
                        {{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;" class="cursor-default">
                    </tr>
                  </table>

Solution

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>

Answered By – ED Wu

Answer Checked By – Mary Flores (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *