Imagine having a vast number of HTML elements with unique IDs that require their styles to be changed repeatedly in a controller for spectrum visualization. What is the most efficient way to achieve this in Angular, without resorting to duplicative HTML code such as:
<div id="spectrumWrapper">
<div class="stapleWrapper">
<div id="sp_1"></div>
</div>
<div class="stapleWrapper">
<div id="sp_2"></div>
</div>
<div class="stapleWrapper">
<div id="sp_3"></div>
</div>
<div class="stapleWrapper">
<div id="sp_4"></div>
</div>
<div class="stapleWrapper">
<div id="sp_5"></div>
</div>
//.. And so on
</div>
Within the .js file:
var sp = []
for(var i = 1; i < 41; i++)
sp[i] = document.getElementById('sp_' + i);
//Some Calculations
for(var i = 1; i < 41; i++)
sp[i].style.height = '' + 50*vecAverageAmp[i-1] +'px';
While this process works effectively, it results in lengthy .html files. Is there a way to utilize ng-repeat
to streamline this approach?