11import { Component , OnInit , AfterViewInit } from '@angular/core' ;
22import Swiper from 'swiper' ;
3+ import { StoreService } from '../../../services/store.service' ;
34
45@Component ( {
56 selector : 'app-skills' ,
@@ -54,17 +55,13 @@ export class SkillsComponent implements OnInit {
5455
5556 slidesPerView = 3 ;
5657
57- constructor ( ) { }
58+ constructor ( private storeService : StoreService ) { }
5859
5960 ngAfterViewInit ( ) {
60- this . mySwiper = new Swiper ( '.skills__body' , {
61- paginationClickable : false ,
62- grabCursor : true ,
63- loop : false ,
64- slidesPerView : this . slidesPerView
65- } ) ;
61+ this . initSwiper ( ) ;
62+ this . mySwiper . destroy ( ) ;
63+ setTimeout ( ( ) => { this . initSwiper ( ) ; } , 20 ) ;
6664 }
67-
6865 previousSlide ( ) {
6966 this . mySwiper . slidePrev ( ) ;
7067 }
@@ -78,12 +75,30 @@ export class SkillsComponent implements OnInit {
7875 if ( window . innerWidth < 600 ) {
7976 this . slidesPerView = 1 ;
8077 }
81- if ( this . mySwiper ) this . mySwiper . reInit ( ) ;
78+ if ( this . mySwiper ) this . mySwiper . update ( ) ;
79+ }
80+ initSwiper ( ) {
81+ this . mySwiper = new Swiper ( '.skills__body' , {
82+ autoplay : 3000 ,
83+ paginationClickable : false ,
84+ grabCursor : true ,
85+ loop : true ,
86+ slidesPerView : this . slidesPerView
87+ } ) ;
8288 }
83-
8489 ngOnInit ( ) {
8590 this . handleSlidesAmount ( ) ;
8691 window . addEventListener ( 'resize' , this . handleSlidesAmount ) ;
92+ this . storeService . bhsLang . subscribe (
93+ ( res ) => {
94+ if ( res ) {
95+ console . log ( 'destroy swiper' ) ;
96+ this . mySwiper . destroy ( ) ;
97+ setTimeout ( ( ) => { this . initSwiper ( ) ; } , 20 ) ;
98+ this . storeService . setLangChanged ( false ) ;
99+ }
100+ }
101+ ) ;
87102 }
88103
89104}
0 commit comments