X Tutup
Skip to content

Commit fd09586

Browse files
bradw2kIgorMinar
authored andcommitted
docs(errors/infdig): add a common example
Mention common cause of error is binding to a new array on every $digest loop. Closes angular#6465
1 parent 713f975 commit fd09586

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/content/error/$rootScope/infdig.ngdoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,28 @@ $scope.$watch('foo', function() {
1414
});
1515
```
1616

17+
One common mistake is binding to a function which generates a new array every time it is called. For example:
18+
19+
```
20+
<div ng-repeat="user in getUsers()">{{ user.name }}</div>
21+
22+
...
23+
24+
$scope.getUsers = function() {
25+
return [ { name: 'Hank' }, { name: 'Francisco' } ];
26+
};
27+
```
28+
29+
Since `getUsers()` returns a new array, Angular determines that the model is different on each `$digest`
30+
cycle, resulting in the error. The solution is to return the same array object if the elements have
31+
not changed:
32+
33+
```
34+
var users = [ { name: 'Hank' }, { name: 'Francisco' } ];
35+
36+
$scope.getUsers = function() {
37+
return users;
38+
});
39+
```
40+
1741
The maximum number of allowed iterations of the `$digest` cycle is controlled via TTL setting which can be configured via {@link ng.$rootScopeProvider $rootScopeProvider}.

0 commit comments

Comments
 (0)
X Tutup