Ubuntu Pastebin

Paste from ericbutters at Thu, 18 Dec 2014 13:46:00 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Why is ng-repeat running *three times* for one index?

Lets say we have a json file we want to run ng-repeat on to presentate.

[
	{
		"meta": 1
	}
]

Doing ng-repeat:

<div ng-repeat="meta_ in metas">
  {{sayHello(meta_,$index)}}
  <h3>{{meta_.meta}}</h3>                                                                                                                                                                                     
</div>

where {{sayHello(x,i)}} does:

$scope.sayHello = function(x,i){
 console.log("LOG: " + x.meta.toString() + " -- LEN: " + $scope.metas.length + " -- IX: " + i.toString() );                                                                                               
}

Output is:

LOG: 1 -- LEN: 1 -- IX: 0 
LOG: 1 -- LEN: 1 -- IX: 0 
LOG: 1 -- LEN: 1 -- IX: 0
Download as text