提供了一个div类型的HTML元素,如何设置其id属性的值,这是范围变量和字符串的串联?
div
id
ngAttr directive can totally be of help here, as introduced in the official documentation
ngAttr
(ngAttr官方文档中所介绍的那样, ngAttr指令在这里可以完全有所帮助)
https://docs.angularjs.org/guide/interpolation#-ngattr-for-binding-to-arbitrary-attributes
(https://docs.angularjs.org/guide/interpolation#-ngattr-for-binding-to-arbitrary-attributes)
For instance, to set the id attribute value of a div element, so that it contains an index, a view fragment might contain
(例如,要设置div元素的id属性值,以便它包含索引,视图片段可能包含)
<div ng-attr-id="{{ 'object-' + myScopeObject.index }}"></div>
which would get interpolated to
(将被内插到)
<div id="object-1"></div>
1.4m articles
1.4m replys
5 comments
57.0k users