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

174
Vistas
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 Respuestas
Responde la pregunta

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 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