Skip to content

Is there a way to detect if background image loaded properly or not in angular? #35503

Closed
@fahadsubzwari924

Description

@fahadsubzwari924

I have an Angular7 app in which I am displaying a div background image. But sometimes link is broken.

My image is bound in my HTML like this

 `<div [ngStyle]="{'background-image': 'url(' + row?.coverUrl + ')', 'background-size': 'cover', 
  'background-position' : 'center'}" class="img-area cursor-pointer" 
  (click)="navigateToCOmpany(row)" *ngIf="row.coverUrl !== ''">
  </div>`

The problem is that sometimes row?.coverUrl is broken link. So how can I detect that link is broken so that I can bind a default image?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions