#change class of a child when clicked
15 messages · Page 1 of 1 (latest)
in this example the <th> click needs to change the class of the <i>
<ng-container cdkColumnDef="firstName">
<th cdk-header-cell *cdkHeaderCellDef (click)="adjustSort('firstName')">
First name
<i class="bi bi-sort-alpha-down"></i>
</th>
<td cdk-cell *cdkCellDef="let user">{{ user.firstName }}</td>
</ng-container>
i'm using the angular cdk table here but that's beside my point
<i> is not child of <td>
did i say it was part of td ?
in the title, yes.
<i> is child of <th> right?
but you're asking about click on td.
fixed the little mistake 😅 i meant th 🤦
Since they're both part of the same view, the simplest solution would be to put a property in the component, bind it to an ngClass for <i>, and change its value with <th>'s (click) output.
or you could do that with pure css.
with pure css?
how would that even work?
the code i posted is a sample of the cdk table
how do i make sure only the <i> inside is targeted? and not a diffrent one?
<ng-container cdkColumnDef="firstName">
<th cdk-header-cell *cdkHeaderCellDef (click)="adjustSort('firstName')">
First name
<i class="bi bi-sort-alpha-down"></i>
</th>
<td cdk-cell *cdkCellDef="let user">{{ user.firstName }}</td>
</ng-container>
<ng-container cdkColumnDef="firstName">
<th cdk-header-cell *cdkHeaderCellDef (click)="adjustSort('lastName')">
First name
<i class="bi bi-sort-alpha-down"></i>
</th>
<td cdk-cell *cdkCellDef="let user">{{ user.lastName}}</td>
</ng-container>
i think i may have found a way