Hey there!
I follow this documentation to use ScreenOrientation in my app : https://ionicframework.com/docs/native/screen-orientation
First, I installed libraries using this steps :
npm install cordova-plugin-screen-orientation
npm install @ionic-native/screen-orientation
ionic cap sync
Then, in my component.ts file, I just imported it and try to declare in my constructor like this :
import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core';
import { IonSlides } from '@ionic/angular';
import { Subscription } from 'rxjs';
import { SliderModel } from './slider.model';
import { HomeService } from '../home.service';
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
@Component({
selector: 'app-slider-images',
templateUrl: './slider-images.component.html',
styleUrls: ['./slider-images.component.scss']
})
export class SliderImagesComponent implements OnInit, OnDestroy {
sliderImgs: SliderModel[];
private sliderImgsSub : Subscription;
isLoaded = false;
@ViewChild('slideWithNav2', { static: false }) slideWithNav2: IonSlides;
sliderTwo: any;
slideOptsTwo = {
initialSlide: 1,
slidesPerView: 2.8,
loop: true,
autoplay: true,
centeredSlides: true,
spaceBetween: 5
};
constructor(private homeService: HomeService, private screenOrientation: ScreenOrientation) {
this.sliderTwo =
{
isBeginningSlide: true,
isEndSlide: false,
slidesItems: []
};
}
ngOnInit() {
this.sliderImgsSub = this.homeService.fetchImage().subscribe(sliderImages => {
this.sliderImgs = sliderImages;
for(let row in this.sliderImgs) {
const imageUrl = {
imageB64: this.sliderImgs[row].imageB64,
};
this.sliderTwo.slidesItems.push(imageUrl);
}
this.isLoaded = true;
});
}
ngOnDestroy() {
if(this.sliderImgsSub) {
this.sliderImgsSub.unsubscribe();
}
}
}
At this moment, I got a problem, this error message is displayed :
Can't resolve all parameters for SliderImagesComponent in /Users/godaltristan/Desktop/Ionic Development/src/app/home/slider-images/slider-images.component.ts: ([object Object], ?).
I also tried to set ScreenOrientation in providers from my app.module.ts but I got the same error message.
I need ScreenOrientation to update the slidesPerView value in my sliderTwo object when orientation change, but I can’t achieved this.
Tried many solutions on many forums but nothing works.
Does anyone have a solution ?
Thanks.