0

i have a list of cards to be displayed in a component. On each card there is a cover-image whose url is coming from server and there is a ngFor in my component.html like this

<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>

Here is how i am getting url in my html. I am attaching chrome inspect element result to show that in html i am getting url but image is not displaying.

enter image description here

Please identify the mistake that what i am doing wrong?

4
  • have you checked the displayed URL is working fine> Commented Nov 7, 2019 at 1:48
  • yes i have checked. It's working fine. Commented Nov 7, 2019 at 1:49
  • do you get a specific message in your console about sanitizing a link? Commented Nov 7, 2019 at 1:56
  • No, i am not getting any kind of warning regarding link sanitizing Commented Nov 7, 2019 at 1:58

2 Answers 2

1

I would try add some height and width to my div

try with random values:

.img-area{
  height:50px;
  width:50px;
}
Sign up to request clarification or add additional context in comments.

6 Comments

yes you are right. It's working. Thanks for the help. :)
can you guide me about one another thing?
@FahadHassanSubzwari sure tell me
I want to check if row.companyId?.coverUrl is exist to put that url in the backgorund property and if not exist so apply hard coded url like ./assets/img/abc.jpg so according to my code how can i do that?
@FahadHassanSubzwari can you make another post I will happy to help I'm just working on this kind of thing and I think I have the answer thanks in advance
|
0

Can you try with ngStyle

<div [ngStyle]="{'background-image': 'url(' + row.companyId?.coverUrl + ')'}" class="img-area">

2 Comments

try to see if you are getting the imag url by printing somewhere {{row.companyId.coverUrl}}
did you see the attached picture in my question? i am getting url in inspect element

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.