Angular 使用*ngFor获取下一个迭代值

Angular 使用*ngFor获取下一个迭代值,angular,indexing,ngfor,Angular,Indexing,Ngfor,我试图在控制器中获得*ngFor循环中下一次迭代的值: 模板: <p *ngFor="let history of histories; let i=index; " [ngClass]="{'show':history.date==dateseeing}"> <span class="history-date">{{ history.date }}</span> <span class="history-txt">{{ histo

我试图在控制器中获得*ngFor循环中下一次迭代的值:

模板:

<p *ngFor="let history of histories; let i=index; "
[ngClass]="{'show':history.date==dateseeing}">
    <span class="history-date">{{ history.date }}</span>
    <span class="history-txt">{{ history.txt }}</span>
    <mat-icon 
        *ngIf="history.date==dateseeing"
        (click)="readNext(history[i+1])">keyboard_arrow_down
    </mat-icon></p>

无法使其工作

如果我没有弄错,请尝试以下方法:

<p *ngFor="let history of histories; let i=index; "
[ngClass]="{'show':history.date==dateseeing}">
    <span class="history-date">{{ history.date }}</span>
    <span class="history-txt">{{ history.txt }}</span>
    <mat-icon 
        *ngIf="history.date==dateseeing"
        (click)="readNext(histories[i+1])">keyboard_arrow_down
    </mat-icon></p>

{{history.date}
{{history.txt}
键盘箭头向下


您不能执行
history[i]
操作,因为历史记录是数组中的项目,并且您希望访问
histories
array

中的第二个项目,您不能执行此操作。这是一个
forOf
循环。在C中考虑<代码> PROACH <代码>,它是这样工作的,很好,很高兴有帮助。
<p *ngFor="let history of histories; let i=index; "
[ngClass]="{'show':history.date==dateseeing}">
    <span class="history-date">{{ history.date }}</span>
    <span class="history-txt">{{ history.txt }}</span>
    <mat-icon 
        *ngIf="history.date==dateseeing"
        (click)="readNext(histories[i+1])">keyboard_arrow_down
    </mat-icon></p>