Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ng-style background image when url contain spaces

I'm trying to apply a background image to a div by using the angular ng-style and it works fine as long as the URL does not contain spaces.

ng-style="{'background-image': 'url(' + parentIMGLink + ')'}"

When there is space in URL like parentIMGLink = servername.images/there is name.png it does not work. On the other hand:

img ng-src={{parentIMGLink }}

Works fine. For sure I can manage so that names on the server wont contain spaces but is there any possibility to make ng-style work?

like image 312
sniegoman Avatar asked Jan 08 '23 03:01

sniegoman


1 Answers

Just like in css you have to wrap your the image url in quotes:

.rule{ background-image: url('/some/image url.png') }

You have to do the same here:

<div ng-style="{'background-image': 'url(\'{{imageUrl}}\')'}">
like image 59
epignosisx Avatar answered Jan 10 '23 18:01

epignosisx