I have problem with background image url. i have array have images url how can I use it in background image url
<div class="col-lg-3 col-md-3 col-sm-6" *ngFor="let course of courses"><a>
</a><div class="box"><a>
<div class="box-gray aligncenter" [style.backgroundColor]="course.imageUrl" >
</div>
</a><div class="box-bottom"><a >
</a><a >{{course.name}}</a>
</div>
</div>
</div>
Refer to this one Angular2 dynamic background images
// inappropriate style.backgroundColor
[style.backgroundColor]="course.imageUrl"
// style.backgroundImage
[style.backgroundImage]="'url('+ course.imageUrl +')'"
thank you for your answers, the correct code is
[ngStyle]="{'background-image':'url(' + course.imageUrl + ')'}">
You should use background
instead of backgroundColor
[style.background]="'url('+course.imageUrl+')'"
you can do it by adding url path in a single variable. for example
bgImageVariable="www.domain.com/path/img.jpg";
and
second way
[ngStyle]="{'background-image': 'url(' + bgImageVariable + ')'}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With