Angular Error: $digest already in progress

由于异步(延迟)的存在,当开始执行回调函数的时候,angularJS自身controller中的脏值检测已经结束,无法检测到回调函数导致数据的变化。导致变化了的数据没有刷新到界面上

解决办法

function apply(scope) {
  if (!scope.$$phase && !scope.$root.$$phase) {
    scope.$apply();
    console.log("Scope Apply Done !!");
  } 
  else {
    console.log("Scheduling Apply after 200ms digest cycle already in progress");
    setTimeout(function() {
        apply(scope)
    }, 200);
  }
}

调用下apply($scope)就可以了

猜你喜欢

转载自blog.csdn.net/a19891024/article/details/76559947