Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

orderBy:random creates infdig errors #6133

Closed
mblase75 opened this issue Feb 5, 2014 · 3 comments
Closed

orderBy:random creates infdig errors #6133

mblase75 opened this issue Feb 5, 2014 · 3 comments

Comments

@mblase75
Copy link

mblase75 commented Feb 5, 2014

Random orderBy sorting works smoothly in angular 1.1.1. It works in 1.2.x as well but generates infdig errors in the console.

http://jsfiddle.net/mblase75/jVs27/

JS:

var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.list = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
$scope.random = function() {
return 0.5 - Math.random();
}
}

error in console:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [["fn: $watchCollectionWatch; newVal: 44; oldVal: 39"],["fn: $watchCollectionWatch; newVal: 49; oldVal: 44"],["fn: $watchCollectionWatch; newVal: 54; oldVal: 49"],["fn: $watchCollectionWatch; newVal: 61; oldVal: 54"],["fn: $watchCollectionWatch; newVal: 67; oldVal: 61"]]
http://errors.angularjs.org/1.2.11/$rootScope/infdig?p0=10&p1=%5B%5B%22fn%3…20%24watchCollectionWatch%3B%20newVal%3A%2067%3B%20oldVal%3A%2061%22%5D%5D
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.js:78:12
at Scope.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.js:11853:19)
at Scope.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.js:12067:24)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.js:1302:15
at Object.invoke (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.js:3707:17)
at doBootstrap (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.js:1300:14)
at bootstrap (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.js:1314:12)
at angularInit (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.js:1263:5)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.js:20752:5
at HTMLDocument.trigger (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.js:2342:7)

@caitp
Copy link
Contributor

caitp commented Feb 5, 2014

You're going to have problems with this because of the instability of the model. You need to return the same array twice in a row to stop the digest from running again, and that's not going to happen like this.

@IgorMinar IgorMinar self-assigned this Feb 6, 2014
@IgorMinar
Copy link
Contributor

right, currently we assume that filters are idempotent (they have no state and return the same value given the same inputs).

I don't see this requirement going away until Angular 2.

To work around this, you could change your app to change the random coefficient outside of the filter function, that will prevent this issue.

@caitp
Copy link
Contributor

caitp commented Feb 6, 2014

Oops, did I forget to close this one again. My bad :(

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants