11import { CommonModule } from '@angular/common' ;
2- import { Component } from '@angular/core' ;
2+ import { Component } from '@angular/core' ;
33
44@Component ( {
55 selector : 'app-slider' ,
66 standalone : true ,
77 imports : [ CommonModule ] ,
88 templateUrl : './slider.component.html' ,
9- styleUrl : './slider.component.scss'
9+ styleUrls : [ './slider.component.scss' ]
1010} )
11- export class SliderComponent {
12- images : string [ ] =
11+ export class SliderComponent {
12+ images : string [ ] =
1313 [
1414 'Assets/slider1.jpg' ,
1515 'Assets/slider2.jpg' ,
1616 'Assets/slider3.jpg' ,
1717 ]
18- currentIndex : number = 0 ;
19- autoSliderInterval ! : number ;
20-
21- ngOnInit ( ) : void
22- {
23- this . startAutoSlider ( ) ;
18+ currentIndex : number = 0 ;
19+ getTransform ( ) : string {
20+ return `translateX(-${ this . currentIndex * 100 } %)` ;
21+ }
22+ next ( ) : void {
23+ if ( this . currentIndex < this . images . length - 1 ) {
24+ this . currentIndex ++ ;
2425 }
25-
26- getTransform ( ) : string
27- {
28- return `translateX(-${ this . currentIndex * 100 } %)` ;
26+ else {
27+ this . reset ( ) ;
2928 }
30- next ( ) : void
31- {
32- if ( this . currentIndex < this . images . length - 1 ) {
33- this . currentIndex ++ ;
34- }
35- else
36- {
37- this . reset ( ) ;
38- }
29+ }
30+ prev ( ) : void {
31+ if ( this . currentIndex > 0 ) {
32+ this . currentIndex -- ;
3933 }
40- prev ( ) : void
41- {
42- if ( this . currentIndex > 0 ) {
43- this . currentIndex -- ;
44- }
45- else
46- {
47- this . reset ( ) ;
48- }
34+ else {
35+ this . reset ( ) ;
4936 }
50- reset ( ) : void
51- {
52- if ( this . currentIndex === 0 ) {
53- this . currentIndex = this . images . length - 1 ;
54- }
55- else
56- {
57- this . currentIndex = 0 ;
58- }
37+ }
38+ reset ( ) : void {
39+ if ( this . currentIndex === 0 ) {
40+ this . currentIndex = this . images . length - 1 ;
5941 }
60- startAutoSlider ( ) : void
61- {
62- this . autoSliderInterval = window . setInterval ( ( ) => {
63- this . next ( ) ;
64- } , 2000 ) ; // Change slide every 2 seconds
42+ else {
43+ this . currentIndex = 0 ;
6544 }
66- }
45+ }
46+ }
47+
0 commit comments