1

Function key_helper gets called many more times than expected.if orderedkeys length is 5 it gets called 25 times instead of 5 times .I am not sure what code to incluce for better understating of my problem.how to make sure it .doesn't repeat

Template:

<td  ng-repeat="key in orderedkeys" >
<div>{{Key_Helper(key)}}</div>
</td>

I tried with a filter:(same problem)

 <td  ng-repeat="key in orderedkeys" >
 <div>{{key | debug}}</div>
 </td>

Function:

$scope.Key_Helper = function(item)
{     
  console.log("key");    
};
Tabraiz Ali
  • 677
  • 9
  • 36

1 Answers1

2

The expression {{}} in not actual JavaScript, this is angular expression. The angular expression allow you to call $scope method and $filter as well.

If any function call occur inside expression then it will execute two times, at first it call the function and second time on the next digest cycle and angular works this way. $filter is a function call. It is better to use simple expression like {{1+1}} or simply value {{key}}. You can check this, this for better understanding.

Community
  • 1
  • 1
Tasnim Reza
  • 6,058
  • 3
  • 25
  • 30