我使用Ngif制作问卷,并使用swiper使其包含很多页面(幻灯片),结构如下:
<div class="swiper-container">
<div class="swiper-wrapper" >
<div class="swiper-slide"> <angular-component1> </div>
<div class="swiper-slide"> <angular-component2> </div>
<div class="swiper-slide"> <angular-component3> </div>
</div>
</div>
angular-component3的内容,例如:
<div> <input type="checkbox" [(ngModel)]=Q1>Q1</div>
<div *ngIf="Q1==true">Q2</div>
<div>some button to click for users</div>
但是当ngif为true时,Q2出来了,DOM发生了变化,并且swiper不会根据Q2的新高度来更新高度,该怎么办?
这是我的刷卡设置:
ngAfterViewInit() {
this.swiper = new Swiper('.swiper-container', {
pagination: {
el: '.swiper-pagination',
type: 'fraction',
},
autoHeight: true,
effect: 'fade',
observer:true,swiper
observeParents:true,swiper
});
this.swiper.on('slideChange', function () {
// window.scroll(0, 0);
});
}