<tr *ngFor="let a of arrayOfObjects">
<td *ngFor="let item of cfValues | keyvalue">
{{item.value}}
</td>
</tr>
I am just trying to print the items in the regular order but the key/value pipe does a default sorting based on the index. Is there a way to disable the default sorting?
You need to return 0 if you want them to not be ordered.
So in your cause you could either do
<td *ngFor="let item of cfValues | keyvalue : 0">
But that would throw a ts error: TypeError: The comparison function must be either a function or undefined
Else, you can create a function that returns 0 and use
function returnZero() {
return 0
}
[... in your template]
<td *ngFor="let item of cfValues | keyvalue : returnZero">
来源:https://stackoverflow.com/questions/54091011/disable-the-default-keyvalue-pipe-sort-in-angular