1

I faced a problem while using the angularjs.

I tested the code below:

function test($scope,$log){
  $scope.a = [
    {name:'John', age:25, gender:'boy'},
    {name:'Jessie', age:30, gender:'girl'},
    {name:'Johanna', age:28, gender:'girl'},
    {name:'Mary', age:28, gender:'girl'},
    {name:'Sebastian', age:50, gender:'boy'},
    {name:'Erika', age:27, gender:'girl'},
    {name:'Samantha', age:60, gender:'girl'}
  ];
  $scope.$log = $log;
}
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<div ng-app>
  <div ng-controller="test">
    <div ng-repeat="as in a">
      {{as.name}}
      {{$log.log('test'+$index)}}
    </div>
  </div>
</div>
</body>
</html>

If you check the console window

test0 angular.js:9509
test1 angular.js:9509
test2 angular.js:9509
test3 angular.js:9509
test4 angular.js:9509
test5 angular.js:9509
test6 angular.js:9509
test0 angular.js:9509
test1 angular.js:9509
test2 angular.js:9509
test3 angular.js:9509
test4 angular.js:9509
test5 angular.js:9509
test6 angular.js:9509

I do not know why the log is taken 14 times.

I hope you give to explain the reason for this.

Also, I think I think will affect the performance ... comments please.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
J.H Shin
  • 11
  • 1

0 Answers0