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

171
Visualizações
Show list of items and when they are more than 2 show mat-menu instead

So I have an array of items. I want to show these items and when they are more than two, a button will show up instead with the number of the remaining items and their name.

 <div *ngFor="let item of items; let i = index">
        <div>
            <div class="avatar" *ngIf=" i<2" />
              {{items.Name}}
            </div>
            <div *ngIf="i >= 2 && items?.length > 2">
               <button class="avatar" mat-button [matMenuTriggerFor]="menu">+ {{items?.length-2}}</button>
            <mat-menu #menu="matMenu">
              <button mat-menu-item>{{items.Name}}</button>
            </mat-menu>
          </div>
        </div>
        </div>

My problems:

  • the button with the number of the rest of the items shows more than once since it is under ngFor, and I need the ngFor to show the item.Name, how to fix that?

  • is there a better way to display the number of the rest of items instead of + {{items?.length-2}}

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

0

you have to choice: 1-

<div *ngIf="i == 2 && items?.length > 2">
               <button class="avatar" mat-button [matMenuTriggerFor]="menu">+ {{items?.length-2}}</button>
            <mat-menu #menu="matMenu">
              <button mat-menu-item>{{items.Name}}</button>
            </mat-menu>
            

2- move button to outside of for and change it to :

<div *ngIf="items?.length > 2">
               <button class="avatar" mat-button [matMenuTriggerFor]="menu">+ {{items?.length-2}}</button>
            <mat-menu #menu="matMenu">
              <button mat-menu-item>{{items.Name}}</button>
            </mat-menu>

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