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

import { Image } from 'src/app/models/typedefs';

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

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

	constructor(private imagesService : ImagesService) {}

	ngOnInit() : void {
		this.imagesService.getImages()
		.subscribe(
			(image : Image) => this.images.push(image)
		);
	}

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

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

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