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 ?
Javascript – How to set the id attribute of a HTML element dynamically with angularjs (1.x)
angularjsangularjs-scopejavascriptstring-concatenation
Related Topic
- Javascript – How to know which radio button is selected via jQuery
- Javascript – Set a default parameter value for a JavaScript function
- Javascript – How to select an element by name with jQuery
- Javascript – How to check if an object is an array?
- Javascript – How does data binding work in AngularJS
- Angularjs – How to access the $scope variable in browser’s console using AngularJS
- Angularjs – the difference between ‘@’ and ‘=’ in directive scope in AngularJS
- Javascript – How to return the response from an asynchronous call
Best Answer
ngAttr
directive can totally be of help here, as introduced in the official documentationhttps://docs.angularjs.org/guide/interpolation#-ngattr-for-binding-to-arbitrary-attributes
For instance, to set the
id
attribute value of adiv
element, so that it contains an index, a view fragment might containwhich would get interpolated to