A better solution would be to store the id of the element that you clicked on, and then if the stored id is the same as the element shown or the corresponding icon, see here you have an example with material icon but the logic is the same for your case.
Example
elementId: number;
toggleArrow(id: number) {
if (id === this.elementId) {
this.elementId = null;
} else {
this.elementId = id;
}
}
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef>Actions</th>
<td mat-cell *matCellDef="let element">
<!--edit button-->
<button type="button" class="btn btn-default" aria-label="Left Align">
<span class="fa fa-pencil-square-o fa-lg" aria-hidden="true"></span>
</button>
<!-- arrow button-->
<button type="button" class="btn btn-default" aria-label="Left Align"
(click)="toggleArrow()">
<span [ngClass]="{
'fa fa-sort-desc fa-lg': element.id === elementId,
'fa fa-caret-right fa-lg': element.id !== elementId}"
aria-hidden="true">
</span>
</button>
</td>
</ng-container>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…