ionic slider does not go to the last photo automatically

0

I've been with ionic for a short time and I do not know if what I'm trying to do can be done, the intention is that according to the user put a photo in a slider the slider go to the last photo put automatically, I have this code and I do not know if I'm on the right track

<ion-slides pager spaceBetween="10">
  <ion-slide *ngIf="images.length === 0">
    <img src="assets/imgs/not-available-es.png" />
  </ion-slide>
  <ion-slide *ngFor="let image of images; let i = index">
    <button ion-button icon-only color="primary" class="remove-image" (click)="removePicture(i)">
      <ion-icon name="trash"></ion-icon>
    </button>
    <img [src]="image" class="photo-image">
  </ion-slide>
</ion-slides>

and the ts

readThis(inputValue: any): void {
if (inputValue.files[0]) {
  let file: File = inputValue.files[0];
  let myReader: FileReader = new FileReader();

  myReader.onloadend = (e) => {
    this.images.push(myReader.result);
    console.log(this.slides.length());
  }
  myReader.readAsDataURL(file);
}
}

    
asked by Carlos 24.07.2018 в 12:55
source

1 answer

0

What you have to do is use the methods provided by the slide. The one you need is slideTo . In your component you have to do something like this

readThis(inputValue: any): void {
  if (inputValue.files[0]) {
    let file: File = inputValue.files[0];
    let myReader: FileReader = new FileReader();

    myReader.onloadend = (e) => {
      this.images.push(myReader.result);
      console.log(this.slides.length());
      // ************************
      this.slides.slideTo(this.slides.length() - 1, 500)
      // ************************
    }
    myReader.readAsDataURL(file);
  }
}
    
answered by 24.07.2018 / 14:40
source