【发布时间】:2019-12-18 16:09:26
【问题描述】:
情景:
我的 Angular 应用程序中有一个要添加背景图像的元素。目前我有这个:
<div class={{background-class}}></div>
其中background-class 是例如“background-style-1”,在我的样式表中是这样的:
background-style-1 {
background-image: url(../../../../assets/images/contextmenu/person.png);
}
问题:
我不想将所有背景图像 URL 硬编码到我的样式表中。相反,我只想将 URL 传递到 HTML 标记中。
我的尝试
<div style="background-image: url(../../../../assets/images/contextmenu/person.png)"></div>
这无法显示图像,当我查询元素时,它显示:
我想知道的:
为什么将图像 URL 作为内联样式属性传递不起作用,如何使其起作用?
【问题讨论】: