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

178
Views
How to replace a broken image URL given in attribute style background-image in Angular?
<img  [src]="item.imgUrl" (error)="pictNotLoading($event)" alt="" />

pictNotLoading(event) { 
    event.target.src = '/assets/dynamic_images/medvibe_partner.png'; 
} 

the above criteria will replace broken images. In my products listing page, I've decided to set background-image dynamically for each product item (as like hover effect).

<span class="product_thumbnail_hover" style="background-image:url('{{item.imgUrl}}');"></span>

But somehow I'm getting a bunch of broken image URLs from api call. So, my question is how to replace a broken image url given in style background-image

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

<ng-template [ngIf]="item.imgUrl != null || item.imgUrl != undefined">
     <span class="product_thumbnail_hover" [ngStyle]="{'background-image': item.imgUrl ? 'url(' + item.imgUrl + ')' : 'url(' + '/assets/dynamic_images/prod_preview.png' + ')'}"></span>
</ng-template>

Above code resolved my issue temporarily. I don't know is this a good or worst method. think this might helps.

about 4 years ago · Juan Pablo Isaza 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!