'mat-autocomplete drop down in alphabetic order
I need put the autocomplete in alphabetic order. How I do this? The autocomplete como from a database and is selected by ID. How can I reorder to alphabetic? I try
this.gestorService = this.getGestores.sort((a,b) => {
if(a.viewValue < b.viewValue) { return -1; }
if(a.viewValue > b.viewValue) { return 1; }
})
But I don't know where I can put this code. And sort come with a error
Property 'sort' does not exist on type '() => void'
my component.html
<mat-label>Gestor</mat-label>
<input type="text"
matInput
formControlName="gestor"
[matAutocomplete]="autoGestor"
[(ngModel)]="ped.gestor"
required>
<mat-autocomplete #autoGestor="matAutocomplete"
[displayWith]="selectGestor">
<mat-option *ngFor="let gestor of filteredGestores | async"
[value]="gestor">
{{gestor.colaborador?.nome}}
</mat-option>
</mat-autocomplete>
my ts
getGestores() {
this.gestorService.getAll().subscribe({
next: gestores => {
this.gestores = gestores;
this.filteredGestores = this.pedForm.get('gestor').valueChanges
.pipe(
startWith(''),
map((value) => {
console.log(value);
return this._filterGestor(value);
}
)
);
}
})
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
