Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
Angular 2: genera un error de lanzamiento de int aleatorio

Tengo una lista en la que estoy usando un número aleatorio para elegir un avatar y arroja el siguiente error:

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

Vista:

 <ion-list> <ion-item *ngFor="let client of clients; let i = index;> <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 "https://randomuser.me/api/portraits/lego/" + num + ".jpg" }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Supongo que puedes probar el truco con background-image y [ngStyle]

HTML

 <ion-list> <ion-item *ngFor="let client of clients; let i = index; let r = getRa" > <ion-avatar item-left> <div class="avatar-photo" [ngStyle]="{ 'background-image': 'url(' + getRandomInt(0, 9) + ')' }"></div> </ion-avatar> </ion-item> </ion-list>

También necesita CSS adicional, por lo que es personalizado, cambie según lo necesite

 .avatar-photo { width: 160px; height: 160px; border-radius: 50%; background-size: contain; background-repeat: no-repeat; }

¡Espero que ayude!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!