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 ?
Join them; it only takes a minute:
|
||||
|
For instance, to set the
which would get interpolated to
|
|||||||||||||||||||||
|
This thing worked for me pretty well:
|
|||||||||||||
|
A more elegant way I found to achieve this behaviour is simply:
For my implementation I wanted each input element in a ng-repeat to each have a unique id to associate the label with. So for an array of objects contained inside myScopeObjects one could do this:
Being able to generate unique ids on the fly can be pretty useful when dynamically adding content like this. |
|||||||||
|
If you use this syntax:
Angular will render something like:
However this syntax:
will generate something like:
|
|||||||||
|
You could just simply do the following In your js
In your template
which will render
It is not necessary to concatenate inside double curly brackets. |
||||
|