Ionic 4 ion-slides change css style of the active slide using ngClass

三世轮回 提交于 2020-01-03 02:24:13

问题


EDIT: adding a stackblitz:

https://stackblitz.com/edit/ionic-b2r7si

I am using ion-slides as following:

<ion-slides class="fullWidth" [options]="slideOptsOne" #slideWithNav
  (ionSlideDidChange)="change($event)">
  <ion-slide #status *ngFor="let array of arrays">
    <ion-col>
      {{array}}
    </ion-col>
  </ion-slide>
</ion-slides>

I need to change the css style of the current active slide, like make it underlined or bold. I've done some researches and apparently I should use [ngClass]='' but can't know how.

I am getting the index of the active slides using:

change(e) {
    this.slides.getActiveIndex().then(
      (index) => {
        this.currentIndex = index;
        console.log(this.currentIndex);
      }
    )
}

I tried:

  <ion-slide #status *ngFor="let array of arrays;let i=index;">
      <ion-col [ngClass]="{'activeIndex': currentIndex==array[i]}">
        {{array}}
      </ion-col>
    </ion-slide>

And activeIndex style:

.activeIndex{
  font-size: 1.5em;
}

But only one element of the array is changed of style.


回答1:


Set the activeIndex class to currentIndex === i. If you set it to array[i], you will get letters of the array instead of the index number you are looking for.

<ion-col [ngClass]="{'activeIndex': currentIndex === i}">
  {{ array }}
</ion-col>

Working stackblitz



来源:https://stackoverflow.com/questions/55146414/ionic-4-ion-slides-change-css-style-of-the-active-slide-using-ngclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!