jeudi 27 avril 2017

Angular 2: Generate random int throws error

I have a list where I am using a random number to choose an avatar and its throwing the following error:

HelloIonicPage.html:33 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.

View:

  <ion-list>
    <ion-item *ngFor="let client of clients; let i = index; let r = getRa" >
      <ion-avatar item-left>
        <img [src]="getRandomInt(0, 9)">
      </ion-avatar>
    </ion-item>
  </ion-list>

.ts

getRandomInt(min, max) {
    let num =  Math.floor(Math.random() * (max - min + 1)) + min;
    return "http://ift.tt/2p7J4LM" + num + ".jpg"
}




Aucun commentaire:

Enregistrer un commentaire