sortBy导致$ digest错误

时间:2014-11-08 08:41:22

标签: angularjs

使用Angular v1.3.2,我试图通过两个参数对对象列表进行排序。第一个是marked,第二个是name。当我按下复选框将checked设置为true时,我在控制台中收到以下错误。

Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.3.1/$rootScope/inprog?p0=%24digest
    at file:///Users/user/Desktop/angular/angular.js:80:12
    at beginPhase (file:///Users/user/Desktop/angular/angular.js:14463:15)
    at Scope.$apply (file:///Users/user/Desktop/angular/angular.js:14207:11)
    at HTMLInputElement.<anonymous> (file:///Users/user/Desktop/angular/angular.js:20803:19)
    at HTMLInputElement.eventHandler (file:///Users/user/Desktop/angular/angular.js:2979:21)
    at forEach.after (file:///Users/user/Desktop/angular/angular.js:3133:14)
    at Object.JQLite.(anonymous function) [as after] (file:///Users/user/Desktop/angular/angular.js:3217:17)
    at Object.enter (file:///Users/user/Desktop/angular/angular.js:4607:23)
    at Object.move (file:///Users/user/Desktop/angular/angular.js:4649:21)
    at ngRepeatAction (file:///Users/user/Desktop/angular/angular.js:24114:26) angular.js:11339(anonymous function) angular.js:11339(anonymous function) angular.js:8415Scope.$apply angular.js:14210(anonymous function) angular.js:20803eventHandler angular.js:2979forEach.after angular.js:3133JQLite.(anonymous function) angular.js:3217enter angular.js:4607move angular.js:4649ngRepeatAction angular.js:24114$watchCollectionAction angular.js:13819Scope.$digest angular.js:13952Scope.$apply angular.js:14214$$debounceViewValueCommit angular.js:20554$setViewValue angular.js:20526listener angular.js:19650eventHandler

这是我的代码:

<!DOCTYPE html>
<html ng-app="myApp">
<head>
  <title>Angular</title>
</head>
<body ng-controller="PersonController">

  <ul>
    <li ng-repeat="person in persons | orderBy: ['marked', 'name']">
      {{person.name}} <input type="checkbox" ng-model="person.marked"
    </li>
  </ul>

  <script src="angular.js"></script>

  <script>
  var myApp = angular.module("myApp", []);

  myApp.controller('PersonController', function ($scope) {
    $scope.persons = [
    {name: "Person1"},
    {name: "Person2"},
    {name: "Person3"}
    ];

  });

  </script>

</body>
</html>

我做错了什么?

0 个答案:

没有答案