Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda