我有很多数据要处理,因此使用ngFor时需要花费一些时间来呈现它。以普通的Jquery方式,我使用了一个循环,当单击更多按钮时,它将呈现下一个10,并使用.append()。由于我使用的是角度,所以我不需要jQuery。如果有的话,建议我另一种方式。
按照说明使用[[trackBy(https://netbasal.com/angular-2-improve-performance-with-trackby-cc147b5104e5)
我们可以通过提供trackBy函数来帮助Angular跟踪添加或删除的项目。 trackBy函数将索引和当前项目作为参数,并需要返回该项目的唯一标识符。现在,当您更改集合时,Angular可以根据唯一标识符跟踪已添加或删除的项目,并仅创建或销毁已更改的项目。<img *ngFor="let picture of pictures; trackBy: trackImageId" [src]="picture.path">
trackImageId(index: number, picture: PictureModel) {
return picture.id;
}
<ng-container *ngFor="let item of list" let-i="index">
<li class="dropdown-item" (click)="onClick(item)" *ngIf="i<11">{{item.text}}</li>
</ng-container
更接近答案{{item.text}}