Reputation: 67
I have an object that I am trying to display in markup. But *ng keeps printing it in ascending order. Desired outcome is for elements to be printed in the order that they are. This is my stackblitz code https://stackblitz.com/edit/angular-5nr2uk
Upvotes: 1
Views: 256
Reputation: 1
As the description in official API doc:
The output array will be ordered by keys. By default the comparator will be by Unicode point value.
This pipe also provides an optional function parameter to re-define sort order:
{{ input_expression | keyvalue [ : compareFn ] }}
(a: KeyValue, b: KeyValue) => number
More detail here
Upvotes: -1
Reputation:
As per the documentation, you can provide a custom compare function to the pipe.
Simply provide a function that returns zero everytime.
customCompare(a, b) {
return 0;
}
*ngFor="let key2 of key.value | keyvalue:customCompare;"
Upvotes: 3