如果有人不知道如何解决它:
<div class="row">
<div class="col-md-1">
<i class="fa fa-chevron-left fa-lg" (click)="prev()" style="cursor: pointer;"></i>
</div>
<div class="col-md-10 row">
<div *ngFor="let image of imageArrayToDisplay">
<div class="col-md-2">
<img [src]="image" />
</div>
</div>
</div>
</div>
<div class="col-md-1">
<i class="fa fa-chevron-right fa-lg" (click)="next()" style="cursor: pointer;"></i>
</div>
</div>
组件:
displayIndex = 0;
displaySize = 5; //No of images to show at the same time
imageArray = ['1.jpg','2,jpg','3.jpg','5.jpg','6.jpg','7,jpg','8.jpg','9.jpg'];
imageArrayToDisplay: string[] = [];
ngOnInit() {
//initially display 5 first images
this.imageArrayToDisplay = this.imageArray.slice(0, this.displaySize);
}
prev() {
this.displayIndex = this.displayIndex - 1;
// Start of list, start at end of list and move backwords
if (this.displayIndex < 0) {
this.displayIndex = (this.imageArray.length/this.displaySize) - 1;
const start = this.displayIndex * this.displaySize;
this.imageArrayToDisplay = this.imageArray.slice(start, (start + this.displaySize));
} else {
const start = this.displayIndex * this.displaySize;
this.imageArrayToDisplay = this.imageArray.slice(start, (start + this.displaySize));
}
}
next() {
this.displayIndex = this.displayIndex + 1;
// End of list, start from beginning
if (this.imageArray.length <= (this.displayIndex * this.displaySize)) {
this.imageArrayToDisplay = this.imageArray.slice(0, this.displaySize);
this.displayIndex = 0;
} else {
const start = this.displayIndex * this.displaySize;
this.imageArrayToDisplay = this.imageArray.slice(start, (start + this.displaySize));
}
}
是的,我想我全部阅读, 呵呵。我发布了我的解决方案,我认为它在与分页相同的街道上:) – Nina