预期的行为:当我在页面中添加多个离子载玻片组件时,我应该能够引用这些载玻片并根据屏幕大小更新其属性。
当前行为:当我在页面上有多个离子载玻片组件并尝试根据屏幕大小更新其属性时,只有最后创建的载玻片组件实际上会使用新设置进行更新。
MovieSliderComponent.html
<ion-slides #Slides class="slides" *ngIf="movies.length > 0" centeredSlides="true" loop="true" slidesPerView="3">
我在HTML中添加了对幻灯片的引用。
MovieSliderComponent.ts
@ViewChild('Slides') slider: Slides;
我将引用应用于变量。
Home.html
<movie-slider #Slider id="nowPlaying" *ngIf="mdata.inTheatres.length > 0" [movies]="mdata.inTheatres">
<movie-slider #Slider id="nowPlayingNearYou" *ngIf="mdata.nearbyShowings.length > 0" [movies]="mdata.nearbyShowings">
<movie-slider #Slider id="genreSuggestions" *ngIf="mdata.suggestedByGenre.length > 0" [movies]="mdata.suggestedByGenre" [showGenres]="true">
我将自己的组件包含在HTML页面中三次。
Home.ts
@ViewChildren('Slider') Slides: MovieSliderComponent[];
我将每个幻灯片引用为一个变量;
setSlidesPerView() {
if(this.platform.width() >= 1200) {
this.Slides.forEach((slider) => slider.slider.slidesPerView = 5);
console.log(this.platform.width());
}
else if(this.platform.width() >= 319 && this.platform.width() < 1200) {
this.Slides.forEach((slider) => slider.slider.slidesPerView = 3);
}
else if(this.platform.width() < 319) {
this.Slides.forEach((slider) => slider.slider.slidesPerView = 1);
}
this.cd.detectChanges();
}
我尝试更改每个滑块的slidesPerView选项,但是只有带有上次创建的Slide-id-2的幻灯片会更新。
指向我原始问题的链接@ ionic-team / ionic-v3 https://github.com/ionic-team/ionic-v3/issues/990
答案 0 :(得分:0)
我通过在每个幻灯片实例上调用slides.resize和slides.update解决了这个问题。