我正在尝试将当前行与下一行进行比较
这是我的代码:
<ng-container *ngFor="let c of my_tab; let i=index">
<ng-container *ngIf="c.id != my_tab[i+1].id">
//do_something
</ng-container>
</ng-container>
但是它不起作用!
答案 0 :(得分:0)
尝试重现您的代码,它可以正常工作。
my_tab = [{id:1, name:'C'},{id:2, name:'A'}, {id:2, name:'A'}, {id:3, name:'A'}];
<div *ngFor="let c of my_tab; let i=index">
<div *ngIf="c.id != my_tab[i+1].id">
not same
</div>
</div>
答案 1 :(得分:0)
我已经解决了问题:
<ng-container *ngFor="let c of my_tab; let i=index">
<ng-container *ngIf="c.id != my_tab[i+1]?.id">
//do_something
</ng-container>
</ng-container>