-
Notifications
You must be signed in to change notification settings - Fork 0
/
carousel.component.ts
30 lines (23 loc) · 799 Bytes
/
carousel.component.ts
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
import { Component, ViewEncapsulation, Output, EventEmitter, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-carousel',
templateUrl: './carousel.component.html',
encapsulation: ViewEncapsulation.None,
styleUrls: ['./carousel.component.scss']
})
export class CarouselComponent implements OnInit{
ngOnInit(){
this.updateIndex.emit(this.currentIndex);
}
@Output() updateIndex = new EventEmitter<number>();
@Input() carouselLength = 0;
currentIndex = 0;
slidePrev() {
this.currentIndex = (this.currentIndex - 1 + this.carouselLength) % this.carouselLength;
this.updateIndex.emit(this.currentIndex);
}
slideNext() {
this.currentIndex = (this.currentIndex + 1) % this.carouselLength;
this.updateIndex.emit(this.currentIndex);
}
}