What is the recommended way to dynamically set background image in Angular 4

后端 未结 3 1335
野性不改
野性不改 2021-01-14 01:40

Currently I\'m setting the image background using inline-style.

3条回答
  •  执念已碎
    2021-01-14 01:57

    This code has worked for me.

    [style.backgroundImage]="'url('+MEDIA_URL +'/dir/'+data.image+')'"
    

    MEDIA_URL is the base URL of uploaded location.

    Angular CLI: 6.1.3 Angular: 6.1.2

提交回复
热议问题