尝试学习一些有关 Angular 2 中的过滤和排序的知识。我似乎找不到任何像样的资源,并且我陷入了如何使用索引以相反的顺序排序 ngFor 输出的问题。我写了下面的管道,它一直给我错误,数组切片不是函数。
@Pipe({
name: 'reverse'
})
export class ReversePipe implements PipeTransform {
transform(arr) {
var copy = arr.slice();
return copy.reverse();
}
}
我的 ngfor 看起来像这样。
<div class="table-row generic" *ngFor="let advert of activeAdverts | reverse let i = index;" [attr.data-index]="i" (click)="viewAd(advert.title)">
<div class="table-cell white-text">{{ i+1 }}</div>
<div class="table-cell white-text">{{advert.title}}</div>
<div class="table-cell green-text">{{advert.advert}}</div>
</div>
我想补充一下.slice()
as well
*ngFor="let advert of activeAdverts.slice().reverse() let i = index;"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)