main.component.ts
734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
}
}