在Angular 5中的任何实例中使用ngFor获取最后显示的项目

在Angular 5中的任何实例中使用ngFor获取最后显示的项目,angular,Angular,我有一个对象,我正在使用*ngFor在HTML中显示它。现在,在任何情况下,我都想知道最后显示的数据 例:- 我有一个对象作为totalItems 现在在HTML中,我将其显示为: <p *ngFor="let item of totalItems"> {{item.Name}} 我想要的是,如果item.Name与上次显示的item.Name相同,则会打印另一个内容。您可以使用*ngIf < *ngFor="let item of totalItems; let las

我有一个对象,我正在使用*ngFor在HTML中显示它。现在,在任何情况下,我都想知道最后显示的数据

例:- 我有一个对象作为totalItems

现在在HTML中,我将其显示为:

<p *ngFor="let item of totalItems">

{{item.Name}}

我想要的是,如果item.Name与上次显示的item.Name相同,则会打印另一个内容。

您可以使用*ngIf

< *ngFor="let item of totalItems; let last = last">
< *ngIf="item.Name == last.Name">
您可以使用ngFor指令中的last

<ng-container *ngFor="let item of totalItems; let last = last">
    <p *ngIf="!last">{{item.Name}}</p>
    <p *ngIf="last">Another thing to display</p>
</ng-container>
将元素包装在容器中,这样就可以同时使用ngFor和ngIf

还有索引、第一、偶数和奇数,您应该阅读文档