错误:[$ rootScope:inprog] $ digest正在使用angular.copy进行中

时间:2014-07-17 10:34:24

标签: angularjs angularjs-scope

我有一个带有ng-blur功能的输入字段。我的模糊函数使用Restangular对服务器执行customPUT,然后执行angular.copy。导致错误的行似乎是angular.copy。

输入字段:

<input type="text" ng-model="le.instance.from" ng-blur="blurField(le.instance.from, $event)">

模糊处理程序

$scope.blurField = function (fieldNewValue, event) {
   $scope.le.instance.customPUT({markSaved: true}).then(function(){
        angular.copy($scope.le.instance, $scope.leSaved);
    });
};

导致问题的一行是angular.copy。我明白这是什么问题,但我不明白为什么做一个角度复制导致另一个摘要运行... 我只是将我的模型对象复制到另一个对象。

同样在我的控制器上,我没有使用任何$ apply或$ digest的电话。

了解/调试此提示的任何提示?

1 个答案:

答案 0 :(得分:0)

当你执行angular.copy时,你确实要运行$ digest进程,因为你通过这样做来改变模型,社区经常提出的解决方案之一就是使用$timeout将副本排队等待另一个摘要

$scope.blurField = function (fieldNewValue, event) {
  $scope.le.instance.customPUT({markSaved: true}).then(function(){
    $timeout(function(){
      angular.copy($scope.le.instance, $scope.leSaved);
    })
  });
};