Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

118
Vistas
Mat-icon change for single row when button clicked

I am implementing mat-table.

Where I want to change the mat-icon of a button based on click event only for single row in the table. I am able to change the icon but not able to do it for only single row.

Any suggestions on how I can fix that?

My stackblitz example: Button-icon change

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You need to have a property that handle value for the individual row. I have added property on array object and setting that expand and collapse.

Here is the working code : https://stackblitz.com/edit/angular-ugxyhc-cbbtmz?file=src%2Fapp%2Ftable-column-styling-example.html

about 4 years ago · Juan Pablo Isaza Denunciar

0

Here is a working fiddle of this: https://stackblitz.com/edit/angular-ugxyhc-ri2neq?file=src%2Fapp%2Ftable-column-styling-example.ts

All you have to do is to expand the object called PeriodicElement to also contain whether he is expanded or not. Once you do that you can ask if a certain element in a certain row is expanded and render accordingly.

export interface PeriodicElement {
  name: string;
  position: number;
  weight: number;
  symbol: string;
  isExpanded?: boolean; // Keep track of expanded state
}
expand(element: PeriodicElement, expanded: boolean) {
   element.isExpanded = !element.isExpanded;
}

And the HTML:

 <td mat-cell *matCellDef="let element">
  <button (click)="expand(element, isExpanded)">
    <mat-icon *ngIf="!element.isExpanded">expand_more</mat-icon>
    <mat-icon *ngIf="element.isExpanded">chevron_right</mat-icon>
  </button>
</td>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda