最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular expression in attribute - Stack Overflow

programmeradmin4浏览0评论

I have a page using angular where im implementing popover from bootstrap:

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

Does angular have an issue w expressions in 'data-' attributes?

Tnx

I have a page using angular where im implementing popover from bootstrap:

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

Does angular have an issue w expressions in 'data-' attributes?

Tnx

Share Improve this question asked Aug 28, 2013 at 12:09 NomzNomz 1512 gold badges2 silver badges13 bronze badges 2
  • is it all happens in ng-repeat ? – Ivan Chernykh Commented Aug 28, 2013 at 12:11
  • It should work. Are the binding not working for this attribute only? – Chandermani Commented Aug 28, 2013 at 13:05
Add a ment  | 

2 Answers 2

Reset to default 11

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 pilation 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 unpiled form (e.g. img[src] or svg's circle[cx] attributes)."

Remove the interpolation notation like this. With {{, }}, AngularJS does string interpolation rather than model binding.

data-content="item.status.message"
发布评论

评论列表(0)

  1. 暂无评论