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,11 @@ 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 ( ) ;
6662 }
67-
6863 previousSlide ( ) {
6964 this . mySwiper . slidePrev ( ) ;
7065 }
@@ -78,12 +73,29 @@ export class SkillsComponent implements OnInit {
7873 if ( window . innerWidth < 600 ) {
7974 this . slidesPerView = 1 ;
8075 }
81- if ( this . mySwiper ) this . mySwiper . reInit ( ) ;
76+ if ( this . mySwiper ) this . mySwiper . update ( ) ;
77+ }
78+ initSwiper ( ) {
79+ this . mySwiper = new Swiper ( '.skills__body' , {
80+ paginationClickable : false ,
81+ grabCursor : true ,
82+ loop : true ,
83+ slidesPerView : this . slidesPerView
84+ } ) ;
8285 }
83-
8486 ngOnInit ( ) {
8587 this . handleSlidesAmount ( ) ;
8688 window . addEventListener ( 'resize' , this . handleSlidesAmount ) ;
89+ this . storeService . bhsLang . subscribe (
90+ ( res ) => {
91+ if ( res ) {
92+ console . log ( 'destroy swiper' ) ;
93+ this . mySwiper . destroy ( ) ;
94+ setTimeout ( ( ) => { this . initSwiper ( ) } , 20 ) ;
95+ this . storeService . setLangChanged ( false ) ;
96+ }
97+ }
98+ ) ;
8799 }
88100
89101}
0 commit comments