<tr *ngFor="let a of arrayOfObjects">
<td *ngFor="let item of cfValues | keyvalue">
{{item.value}}
</td>
</tr>
我只是想按常规顺序打印项目,但是键/值管道会根据索引进行默认排序。
有没有办法禁用默认排序?
最佳答案
如果您不希望订购它们,则需要返回0。
因此,根据您的原因,您可以<td *ngFor="let item of cfValues | keyvalue : 0">
但这会引发ts错误:TypeError: The comparison function must be either a function or undefined
否则,您可以创建一个返回0的函数并使用
returnZero() {
return 0
}
[...在您的模板中]<td *ngFor="let item of cfValues | keyvalue : returnZero">
关于angular - 禁用默认的键值管道排序 Angular ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54091011/