I'm looping through lots of data. Each object has a property startTime and duration, which is unique for each object.
I need to do calculations on this startTime and duration for each object in the array and set the elements width based off these calculations.
<div ng-repeat = "event in events track by event.id">
<div style="width:{{calculateWidth(event.startTime, event.duration)}}%">
<div>more content</div>
</div>
<div>
and my js
$scope.calculateWidth = function(duration, starTime){
var secondsInDay = 86400;
var width = (duration / secondsInDay)*100;
return width;
}
I simplified my code for example purpose and there are more calculations I omitted. Overall, This works fine for less than 30 objects but performance lacks as the data grows.
Is there a better way to do this in Angular?
startTimeanddurationchange once the width has been calculated once? If not you could use one time bindings or simply precalculate it.