Thierry Marianne Thierry Marianne - 1 month ago 8x
AngularJS Question

How to set the id attribute of a HTML element dynamically with angular js?

Provided an HTML element of type

, how to set the value of its
attribute, which is the concatenation of a scope variable and a string ?


ngAttr directive can totally be of help here, as introduced in the official documentation
Update: documentation moved to:

For instance, to set the id attribute value of a div element, so that it contains an index, a view fragment might contain

<div ng-attr-id="{{ 'object-' + myScopeObject.index }}"></div>

which would get interpolated to

<div id="object-1"></div>