typescript - Cómo desactivar el ordenamiento automático de pares clave-valor en Angular 6
He creado un arreglo en mi archivo ts y con ngFor obtengo elementos del arreglo, pero cuando uso key value Angular ordena automáticamente el arreglo. ¿Cómo guardar el orden como se creó el arreglo?
Código TS:
filterListingTypeItems: { [key: string]: object } = {
'For sale': [
'For sale',
'By Agent',
'By ownre',
'New Construction',
'Foreclosures',
'Coming Soon',
],
'Potential listings': [
'Potential listings',
'Foreclosed',
'Pre-Foreclosure',
'Make Me Move',
],
'For Rent': ['For Rent'],
'Recently sold': ['Recently sold'],
_________________________: ['Open House only', 'Pending & Under Contract'],
}
Código HTML (Angular Material):
<mat-optgroup
*ngFor="let listingOptions of (filterListingTypeItems | keyvalue)"
[label]="listingOptions.key"
>
<mat-option
*ngFor="let listingOption of listingOptions.value"
[value]="listingOption"
>{{ listingOption }}</mat-option
>
</mat-optgroup>
se vuelve así (img)
Respuesta #1
puedes crear una función que devuelva 0 en el archivo ts del componente.
function returnZero() {
return 0
}
Dentro del archivo de plantilla
<td *ngFor="let item of cfValues | keyvalue : returnZero">
Respuesta #2
No creaste un arreglo sino un objeto. Así que no hay orden en primer lugar.
Si necesitas un orden, haz un arreglo en lugar de un objeto.
filterListingTypeItems = [
{
key: 'For sale',
value: [
'For sale',
'By Agent',
'By ownre',
'New Construction',
'Foreclosures',
'Coming Soon',
]
},
...
]
