gpt4 book ai didi

css - 为什么背景图像的 ng-style 不起作用?

转载 作者:太空宇宙 更新时间:2023-11-03 18:05:57 25 4
gpt4 key购买 nike

我的ng-style如下,对后台不起作用:

<div
ng-repeat="s in slider.slides"
class="slide"
ng-style="{border: 'solid 4px red', 'background-image': 'url(rsc/selectiontodose/{{s.photo}}.jpg)'}"
style="width: {{size}}px; height: {{size}}px; margin:0; left:{{-$parent.slide*size}}px;">
</div>

我添加了边框以确保 hg-style 指令本身被考虑在内(因为边框是红色的)。

在 DOM 中,我看不到背景,而实际上有边框。

有什么想法吗?

最佳答案

有过类似的情况,我发现:

<div class="splash-banner" ng-style="{'background-image': 'url(\'{{banner.backgroundImage}}\')', 'background-color': banner.backgroundColor}">

与以下相比会呈现不一致:

<div class="splash-banner" ng-style="{'background-image': 'url(\'' + banner.backgroundImage + '\')', 'background-color': banner.backgroundColor}">

不幸的是,我不太了解 Angular ,但似乎 ng 风格的表达式会在 {{banner.backgroundImage}} 有值之前评估它。我想知道这是否是因为横幅元素是从 REST 请求中检索到的。然后它将默认为当前页面的 url(或至少是当前主机名)。

关于css - 为什么背景图像的 ng-style 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24664107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com