网址包含空格时的角度ng样式背景图片 [英] Angular ng-style background image when url contain spaces

查看:81
本文介绍了网址包含空格时的角度ng样式背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用角度ng-style将背景图像应用于div,只要URL不包含空格,它就可以正常工作.

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

URL中的空格如parentIMGLink = servername.images/there is name.png时不起作用.另一方面:

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 }}

工作正常.当然可以管理,以便服务器上的名称不会包含空格,但是是否有可能使ng样式起作用?

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?

推荐答案

就像在CSS中一样,您必须将图片网址用引号引起来:

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}}\')'}">

这篇关于网址包含空格时的角度ng样式背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆