I am iterating over an array of 5 elements, and I call a function 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>
in the console it appears that this function is being called in total 40 times, when the array has only 5 elements, then this function should be used only 5 times in this case.
this is my code:
<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";
}
});
I have a real example where I have a series of more complex operations and libraries that I could not include. but this small example helps me explain my problem.
What am I doing wrong?
Link updated: