[英]AngularJS - inline css style rendering
Is it possible / and how / to write inline css style using angular variables? 是否可能/以及如何/使用角度变量编写内联css样式?
<div style="background: transparent url({{eventInfo.eventHeaderImg}}) top center no-repeat;"></div>
This is my output 这是我的输出
"NetworkError: 404 Not Found - http://test/eventInfo.eventHeaderImg"
So I see it didn't render this value. 所以我看到它没有呈现这个价值。
I know it's possible to change this in controller, but is it doable with my approach? 我知道可以在控制器中更改它,但是我的方法是否可行?
an example: http://plnkr.co/edit/qT8skZzTwXjrh3Ye5mr9?p=preview 一个例子: http : //plnkr.co/edit/qT8skZzTwXjrh3Ye5mr9?p = preview
<div ng-style="{ background: 'transparent url({{ eventInfo.eventHeaderImg }}) top center no-repeat' }"></div>
这对我有用:
<div ng-style="{ 'background': 'transparent url(' + eventInfo.eventHeaderImg + ') top center no-repeat' }"></div>
You're "writing" a wrong url in your style, that's why you've got a 404
(not found) error. 你正在“写”一个错误的网址,这就是为什么你有一个404
(未找到)错误。
According to this plunker , if you're $scope
is well set up, you print the right data in style
attribute. 根据这个plunker ,如果你的$scope
设置得很好,你可以在style
属性中打印正确的数据。
Note that your eventInfo
scope variable has to be a map/object. 请注意,您的eventInfo
范围变量必须是地图/对象。
您不需要在那里使用双卷曲支架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.