When looping through an array of 5 elements, a function is being called inside the ng-repeat.
$scope.myArray=[1,2,3,4,5]
var i=0;
$scope.diffHours= function(){
i++;
console.log(i)
return "string";
}
<div ng-repeat="item in myArray">
{{diffHours()}}
</div>
Surprisingly, the function is being called 40 times in total instead of just 5 times corresponding to the array elements.
https://i.sstatic.net/G8HHj.png
This is the code snippet:
<script id="view.html" type="text/ng-template">
<ion-view view-title="Second page">
<ion-content class="padding">
<div ng-repeat="item in myArray">
{{diffHours()}}
</div>
</ion-content>
</ion-view>
nameApp.controller('ViewCtrl', function($scope, $stateParams, $ionicHistory)
{
$scope.myArray=[1,2,3,4,5]
var i=0;
$scope.diffHours= function(){
i++;
console.log(i)
return "string";
}
});
This scenario showcases a simplified version of my issue, though I have more complex operations and libraries in my actual project that are not displayed here.
Any insights on what could be causing this?
Updated link below: