Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

385
Views
ordenar el menú alfabéticamente en angular

Estoy tratando de averiguar si hay una para ordenar los elementos (botones) dentro del menú en orden alfabético por medio de una función en el archivo mecanografiado, por favor, el siguiente código que usa material angular.

 <mat-menu #menu3="matMenu" [overlapTrigger]="false"> <button mat-menu-item [routerLink]="['A']">A</button> <button mat-menu-item [routerLink]="['C']">C</button> <button mat-menu-item [routerLink]="['D']">D</button> <button mat-menu-item [routerLink]="['B']">B</button> </mat-menu>
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Puede agregar los elementos del menú en una matriz, ordenar la matriz y luego representarla usando *ngFor , algo similar a:

 public menuItems: string[] = ["C", "B", "A"]; // use sort() to sort the array in ngOnInit() or wherever convenient ngOnInit() { this.menuItems = this.menuItems.sort(); }

luego, en la plantilla, vincule la matriz ordenada a *ngFor

 <mat-menu #menu3="matMenu" [overlapTrigger]="false"> <button mat-menu-item *ngFor="let item of menuItems" [routerLink]="[item]">{{ item }} </button> </mat-menu>

Consulte MDN para ver los documentos de sort() Aquí para obtener una clasificación personalizada, etc.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!