twitter-bootstrap 属性中的角度表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18487480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Angular expression in attribute
提问by Nomz
I have a page using angular where im implementing popover from bootstrap:
我有一个使用 angular 的页面,我在其中从引导程序实现了弹出窗口:
<img class="state-msg" data-toggle="popover" ng-popover data-content="{{item.status.message}}" data-trigger="hover" data-placement="top" ng-src="{{item.status.stateIcon}}"/>
The data-content doesnt get rendered correctly. It returns literaly {{item.status.message}} instead of the value of message.
数据内容未正确呈现。它返回字面意思 {{item.status.message}} 而不是消息的值。
Does angular have an issue w expressions in 'data-' attributes?
angular 在“数据-”属性中是否存在 w 表达式问题?
Tnx
田纳西州
采纳答案by zs2020
Remove the interpolation notation like this. With {{, }}, AngularJS does string interpolation rather than model binding.
删除这样的插值符号。使用{{, }},AngularJS 进行字符串插值而不是模型绑定。
data-content="item.status.message"
回答by augustoht
You can try this out:
你可以试试这个:
ng-attr-src="{{item.status.stateIcon}}"
From documentation:
从文档:
"If an attribute with a binding is prefixed with ngAttr prefix (denormalized prefix: 'ng-attr-', 'ng:attr-') then during the compilation the prefix will be removed and the binding will be applied to an unprefixed attribute. This allows binding to attributes that would otherwise be eagerly processed by browsers in their uncompiled form (e.g. img[src] or svg's circle[cx] attributes)."
“如果具有绑定的属性以 ngAttr 前缀为前缀(非规范化前缀:'ng-attr-'、'ng:attr-'),则在编译期间,该前缀将被删除,并且该绑定将应用于无前缀的属性。这允许绑定到浏览器以未编译形式急切处理的属性(例如 img[src] 或 svg 的 circle[cx] 属性)。”

