In my Angular 7 application, I am displaying a background image in a div
. However, there are instances when the link to the image is broken.
The way I bind the image in my HTML is as follows:
<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 issue arises when the row?.coverUrl
turns out to be a broken link. Is there a way to detect this so that I can assign a default image instead?