Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

Provided an HTML element of type div, how to set the value of its id attribute, which is the concatenation of a scope variable and a string?

 

1 Answer

0 votes
by (106k points)

To set the id attribute of an HTML element dynamically with angularjs (1.x) ngAttr directive can be used.

Here’s the code:-

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

The above code will get interpolated into:-

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

Related questions

0 votes
1 answer
+2 votes
1 answer
+2 votes
1 answer
0 votes
1 answer

Browse Categories

...