【发布时间】:2018-04-30 20:32:35
【问题描述】:
我试图在控制器中获取 *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>
控制器:
public readNext(history) {
console.log(history);
const date = history.date;
this.dateseeing = date;}
做不出来
【问题讨论】:
-
你不能那样做。这是一个
forOf循环。考虑 C# 中的foreach,它的工作原理是这样的。