0

Код из класса:

export class WinsPage {

  public imgList: any;


  public loadGallery():void{
    let options ={
      maximumImagesCount: 20,
      width: 500,
      height: 500,
      quality: 75
    };
    this.imagePicker.getPictures(options).then(function (result) {
      for (let i = 0; i < result.length; i++) {
        this.imgList = [{id: result[i], title: result[i]}];
      }
    });
}

Код страницы где хочу обработать и получить из imgList данные:

<ion-header>
    <ion-toolbar>
      <ion-title>Мои победы</ion-title>
      <ion-buttons end>
        <button ion-button icon-only (click)="loadGallery()">
          <ion-icon name="ios-add-circle-outline"></ion-icon>
        </button>
      </ion-buttons>
    </ion-toolbar>
</ion-header>

<ion-content>
  <ion-grid>
    <ion-row responsive-sm><!-- responsive-sm = test -->
      <ion-col col-4 *ngFor="let item of imgList">
        <img src="{{item.id}}" (click)="loadWin(item.id)" />
      </ion-col>
    </ion-row>
  </ion-grid>

</ion-content>

Не грузит в img ссылки на картинки и в консоли возвращает ошибку: Error: Uncaught (in promise): TypeError: Cannot read property 'imgList' of undefined imgList же объявлен. Пробовал менять на public imgList: [] и public imgList: any[]=[]; Всё равно ошибка

1 ответ 1

0

В силу того что только начал изучать typescript, не правильно обрабатывал this в обратной функции (кажется так называется). Заменил function на => в imagePicker.getPictures на

this.imagePicker.getPictures(options).then((result) => {....

И случилось чудо)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.