main.component.ts 734 Bytes
import { Component, OnInit } from '@angular/core';
import { ImagesService } from 'src/app/services/images.service';

export interface Image {
	url : string;
	alt : string | null;
}

@Component({
	selector: 'main',
	templateUrl: './main.component.html',
	styleUrls: ['./main.component.css']
})
export class MainComponent implements OnInit {

	images : string[];
	selected : number = 0;

	constructor(private fetch : ImagesService) { }

	ngOnInit(): void {
		this.images = this.fetch.get();
	}

	select(s : number) {
		this.selected = s % this.images.length;
	}

	next() {
		this.selected = (this.selected + 1) % this.images.length
	}

	previous() {
		this.selected = (this.selected - 1 + this.images.length) % this.images.length
	}

}