Last active
April 27, 2023 09:56
-
-
Save samuelkavin/da85847be08adaf4d66b4de81a7d62fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imageCollection: string[]; | |
selectedImage: string; | |
imageIndex: number; | |
currentImage: string; | |
constructor( | |
public dialogRef: MatDialogRef<LigthboxModalComponent>, | |
@Inject(MAT_DIALOG_DATA) public data: any | |
) {} | |
ngOnInit() { | |
this._processImageList(); | |
} | |
next() { | |
if (this.imageIndex === this.imageCollection.length - 1) { | |
this.imageIndex = 0; | |
} | |
this.currentImage = this.imageCollection[(this.imageIndex += 1)]; | |
} | |
prev() { | |
if (this.imageIndex === 0) { | |
this.imageIndex = this.imageCollection.length - 1; | |
} | |
this.currentImage = this.imageCollection[(this.imageIndex += -1)]; | |
} | |
_processImageList() { | |
const rawData = this.data.imageCollection.tabDetails; | |
this.imageCollection = rawData.flatMap((el: any) => el.imageData); | |
this.imageIndex = this.imageCollection.findIndex((x) => x === this.data.selectedImage); | |
this.currentImage = this.imageCollection[this.imageIndex]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment