Warm tip: This article is reproduced from stackoverflow.com, please click
angularjs

Why am I getting RangeError: Maximum call stack size exceeded when watching for change to parent sco

发布于 2020-04-08 09:43:00

My problem is I want to watch for changes to a filtered array created with ng-repeat, for that I'm referencing to the parent scope since I've learned ng-repeat creates its own scope, and while watching the array with $scope.$watch actually works (it accurately detects changes to the array), I get multiple console log errors saying: angular.js:12520 RangeError: Maximum call stack size exceeded. Anyone have any inputs to what I can do to solve the problem?

HTML: <div class="module-card" ng-repeat="module in ($parent.filteredModules = (modules | released : true | moduleFilter : allFilters | unique: 'name' | orderBy : sortFunc : orderedAsc | limitTo : limitResults)) track by $index">

JS:

$scope.$watch('filteredModules', function(newVal, oldVal){
   console.log(newVal, oldVal);
}, true)
Questioner
marjon4
Viewed
49
marjon4 2020-01-31 20:33

Solved the problem by using $scope.$watchCollection instead.. If anyone bumps into the same problem.