aboutsummaryrefslogtreecommitdiffstats
path: root/docs/content
diff options
context:
space:
mode:
authorBrad Williams2014-02-26 14:27:17 -0800
committerIgor Minar2014-02-26 16:33:59 -0800
commitfd09586b08cf40cedd59fe4de944000a3ebf6a59 (patch)
treeaf3bb726819baa153f9b589b71eb8328756bee43 /docs/content
parent713f9758e212179c360ed8c4a460f6e66028c0a8 (diff)
downloadangular.js-fd09586b08cf40cedd59fe4de944000a3ebf6a59.tar.bz2
docs(errors/infdig): add a common example
Mention common cause of error is binding to a new array on every $digest loop. Closes #6465
Diffstat (limited to 'docs/content')
-rw-r--r--docs/content/error/$rootScope/infdig.ngdoc24
1 files changed, 24 insertions, 0 deletions
diff --git a/docs/content/error/$rootScope/infdig.ngdoc b/docs/content/error/$rootScope/infdig.ngdoc
index e36f1d69..d6261df1 100644
--- a/docs/content/error/$rootScope/infdig.ngdoc
+++ b/docs/content/error/$rootScope/infdig.ngdoc
@@ -14,4 +14,28 @@ $scope.$watch('foo', function() {
});
```
+One common mistake is binding to a function which generates a new array every time it is called. For example:
+
+```
+<div ng-repeat="user in getUsers()">{{ user.name }}</div>
+
+...
+
+$scope.getUsers = function() {
+ return [ { name: 'Hank' }, { name: 'Francisco' } ];
+};
+```
+
+Since `getUsers()` returns a new array, Angular determines that the model is different on each `$digest`
+cycle, resulting in the error. The solution is to return the same array object if the elements have
+not changed:
+
+```
+var users = [ { name: 'Hank' }, { name: 'Francisco' } ];
+
+$scope.getUsers = function() {
+ return users;
+});
+```
+
The maximum number of allowed iterations of the `$digest` cycle is controlled via TTL setting which can be configured via {@link ng.$rootScopeProvider $rootScopeProvider}.