Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
How can my users click a button while it's parent component is re-rendering frequently?

I am having the following setup (the below is simplified pseudocode):

<table>
  <tr *ngFor="let upload in uploads">
   <td>
     <app-progress-bar [progress]="upload.progress"></app-progress-bar>
   </td>
   <td>
     <button (click)="cancelUpload(upload.id)>x</button>
   </td>  
  </tr>
</table>

now, upload will change frequently while progress is being updated. This causes a re-render of the entire row including the button, which makes it very hard to actually trigger the buttons click event. If I click multiple times I'd eventually make it, but I don't think this would make for a good ux...

I think I am must be missing something simple, because I would believe I am not the only person with a similar use case, but I was not able to find any solution - except for moving the button out of the table and having a separate loop through only the array of upload-ids to build the buttons.

I'd highly appreciate if someone could send me on the right track again!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

In the end adding the trackBy-function - or in my case trackByRow because I am working with a primeng-table did the trick. I don't fully understand why, because I though trackBy is there to ensure that no other rows are being updated, by my problem was that the actually affected row re-rendered.

But with the trackBy-function in place, when I inspect the dom I see that only the progress-parameter passed to my app-progress-bar component changes, nothing else. And my cancel button works :)

about 4 years ago · Juan Pablo Isaza Relatório

0

<table>
  <tr *ngFor="let upload of uploads; ; let id = index">
   <td>
     <app-progress-bar [progress]="upload.progress"></app-progress-bar>
   </td>
   <td>
     <button (click)="cancelUpload(id)>x</button>
   </td>  
  </tr>
</table>

If your upload.id is the same as the index , you can use the index to get the id.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda