angular 4 style background image when using ngFor angular 4 style background image when using ngFor json json

angular 4 style background image when using ngFor


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+')'"