I have a collection of cards that need to be shown in a component
. Each card contains a cover-image
with an URL fetched from the server. In my component.html
, I am using ngFor as follows:
<div [style.background-image]="'url('+row.companyId?.coverUrl+')'" class="img-area">
</div>
<div class="card-content-area">
<p class="card-title cursor-pointer" (click)="navigateToCOmpany(row)">{{row.companyId.name}}</p>
<div class="card-description-area">
<p class="site-text">{{row.offer_desc}}</p>
</div>
<a (click)="referralClick(row, i)" class="site-btn show-desktop-block">Get referral link</a>
<a (click)="referralClick(row, i)" class="site-link-mobile show-mobile-block"><i class="fa fa-link mobile-link" aria-hidden="true"></i> Get Referral link</a>
</div>
The cover images are retrieved in row.companyId.coverUrl
. If row.companyId.coverUrl
does not exist in the API response, I want to use a hardcoded URL like ./assets/img/abc.jpg
for the background instead.
How can I achieve this?