Home > Back-end >  How can I add background image to Angular selector?
How can I add background image to Angular selector?

Time:02-20

I am trying to add background image to Angular selector, but its not working for me. Below is the code

    <app-highway-card [ngStyle]="{'background-image':'url(https://cdn.pixabay.com/photo/2021/09/04/09/32/road-6597404__340.jpg)'}" [highway]="highway"></app-highway-card>

CodePudding user response:

Add display: 'block' to the styles:

[ngStyle]="{'background-image':'url(https://cdn.pixabay.com/photo/2021/09/04/09/32/road-6597404__340.jpg)', display: 'block'}"

Stackblitz: https://stackblitz.com/edit/angular-ivy-zmjsjo?file=src/app/app.component.html

  • Related