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

175
Visualizações
Get updated value of mat-paginator attributes - MatPaginator

As I can't comment on this question, I am making this question 'again'.

So, I have a custom paginator component built over MatPaginator implementation. Its data comes from a service:

@Injectable()
export class PageService extends MatPaginatorIntl {
  itemsPerPageLabel = 'Register by page';

  getRangeLabel = function (page, pageSize, length) {
    if (length === 0 || pageSize === 0) {
      return 'Page 0 of ' + length;
    }
    length = Math.max(length, 0);
    const startIndex = page + 1;
    const remainder = length % pageSize;
    let totalPages = Math.floor(length / pageSize);
    totalPages = remainder > 0 ? totalPages + 1 : totalPages;

    return 'Page ' + (startIndex) + ' of ' + totalPages;
  };
}

Main data of component:

  ngAfterViewInit() {
    const paginatorOriginalText = this.paginator.nativeElement.querySelector('.mat-paginator-range-label');
    const currentPage = paginatorOriginalText.innerHTML.split(' ')[1];
    setTimeout(() => {
      const totalPages = paginatorOriginalText.innerHTML.split(' ')[3];
      paginatorOriginalText.innerHTML = `Page <input class="current-page-input" type="text" value="${currentPage}"> of <span>${totalPages}</span>`;
    }, 1000);
  }

Issue is: totalPages value only gets updated value after 1000ms, as above code. That solution was so proposed on first link up there.

Is there any clean, elegant solution for this nowadays?

about 4 years ago · Juan Pablo Isaza
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