If you want to display different images in your carousel each time the page is viewed, consider randomizing your primary Array (the array with images). This way, every new visit to the page will showcase a unique sequence of images.
Here's how you can achieve this:
<ngu-carousel #myCarousel [inputs]="carouselConfig" [dataSource]="carouselItems">
<div *nguCarouselDef="let item;" class="item">
<div class="tile">{{item}}</div>
</div>
<button NguCarouselNext class="rightRs">></button>
<button NguCarouselPrev class="leftRs"><</button>
<ul class="myPoint" NguCarouselPoint>
<li *ngFor="let j of myCarousel.pointNumbers; let j = index" [class.active]="j==myCarousel.activePoint" (click)="myCarousel.moveTo(j)"></li>
</ul>
</ngu-carousel>
To implement this functionality in your Angular application, include the following code snippet in your component file:
import { Component, AfterViewInit, ViewChild, ChangeDetectorRef } from '@angular/core';
import { NguCarousel, NguCarouselConfig } from '@ngu/carousel';
@Component({
selector: 'app-simple',
templateUrl: './simple.component.html',
styleUrls: ['./simple.component.css']
})
export class SimpleComponent implements AfterViewInit {
name = 'Angular';
slideNo = 0;
withAnim = true;
resetAnim = true;
@ViewChild('myCarousel') myCarousel: NguCarousel;
carouselConfig: NguCarouselConfig = {
grid: { xs: 1, sm: 1, md: 1, lg: 1, all: 0 },
load: 3,
interval: { timing: 4000, initialDelay: 1000 },
loop: true,
touch: true,
velocity: 0.2
}
carouselItems: any[];
constructor(private cdr: ChangeDetectorRef) {
let myArray: any[] = ['item 1', 'item 2', 'item 3'];
myArray = this.shuffleArray(myArray);
this.carouselItems = myArray;
}
shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
ngAfterViewInit() {
this.cdr.detectChanges();
}
reset() {
this.myCarousel.reset(!this.resetAnim);
}
moveTo(slide) {
this.myCarousel.moveTo(slide, !this.withAnim);
}
}
For a live demonstration and further exploration, you can check out the working stackblitz here.