admin管理员组文章数量:1291122
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?
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?
Share Improve this question asked Jun 15, 2015 at 8:03 sniegomansniegoman 592 silver badges6 bronze badges 2-
what do you mean by
does not work
? – Hacketo Commented Jun 15, 2015 at 8:11 - @Hacketo Probably that it won't find the image... – Gustaf Gunér Commented Jun 15, 2015 at 8:12
2 Answers
Reset to default 7Just 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}}\')'}">
You can try this. In JS, replace " " with %20 (Percent-encoded space).
parentIMGLink = parentIMGLink.replace(" ", "%20");
本文标签: javascriptAngular ngstyle background image when url contain spacesStack Overflow
版权声明:本文标题:javascript - Angular ng-style background image when url contain spaces - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741511894a2382654.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论