I'm using mat-table
from @angular/material
in one of my projects. And I need to access <tbody>
<table mat-table matSort [dataSource]="someSource">
<ng-container matColumnDef="date">
<th mat-header-cell *matHeaderCellDef>Date</th>
<td mat-cell *matCellDef="let some">{{some.field}}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>
My question is: how can I access tbody
tag to add some project-specific attributes?
It's not for CSS styling. Otherwise, it would be simple. I just need it to have attr="value"
You can do something like below. Use
ViewChild
and angular lifecycle hookAfterViewInit
Working stackblitz
In the template file
In the ts file