Angularjs [$ rootScope:inprog] INPROGRESS错误 [英] Angularjs [$rootScope:inprog] inprogress error

查看:730
本文介绍了Angularjs [$ rootScope:inprog] INPROGRESS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到angularjs [$ rootScope:inprog]。误差

错误:[$ rootScope:inprog] http://errors.angularjs.org/1.2.7/$rootScope/inprog?p0=%24digest.

这是函数调用

  Members.get({}功能(响应){//成功
   $ scope.family_mem = response.data;
  },功能(错误){// AJAX加载错误    Data.errorMsg(); //显示错误通知
  });

在控制台我得到由PHP控制器结果function.but没有更新 $ scope.family_mem 而不是去错误的部分。
这是在指令

  myApp.directive('mySelect',函数(){
  返回{
    限制:'A',
    链接:功能(范围,元素){
      $(元件).select2();
    }
  };
});


解决方案

通常这意味着你定义$ rootScope。$某处手动应用的另一角code具有生命周期已经内部。这不应该在共同案件角轨道生命周期本身发生。它是一个需要常见的情况是,当你需要更新的无棱角code(像jQuery或老式的JS的东西)的范围。所以,请检查您是否有这样的地方。如果你真的需要它更好地使用安全应用(普通code段):

  angular.module('主',[])。服务('scopeService',函数(){
     返回{
         safeApply:函数($范围,FN){
             VAR相= $ $范围根$$阶段。;
             如果(相=='$申请'||阶段=='$消化'){
                 如果(FN&安培;&安培; typeof运算FN ==='功能'){
                     FN();
                 }
             }其他{
                 。$ $范围应用(FN);
             }
         },
     };
});

然后你可以注入这个服务,并进行必要的呼叫:

  scopeService.safeApply($ rootScope,函数(){
    //你在这里code将更改应用于范围
});

I am getting angularjs [$rootScope:inprog] error.

Error: [$rootScope:inprog] http://errors.angularjs.org/1.2.7/$rootScope/inprog?p0=%24digest.

this is the function calling

 Members.get({}, function (response) { // success
   $scope.family_mem = response.data;    
  }, function (error) { // ajax loading error

    Data.errorMsg(); // display error notification
  });

in console i am getting results by php controller function.but not updating $scope.family_mem instead going to error part. this is the directive

myApp.directive('mySelect', function() {
  return{
    restrict: 'A',
    link: function(scope, element){
      $(element).select2();
    }
  };
});

解决方案

Usually this means that you defined $rootScope.$apply somewhere manually inside of the another angular code which has lifecycle already. This should not be happen in common cases as angular tracks the lifecycle itself. The one common case where it is needed is when you need to update scope from non-angular code (like jquery or old-fashioned js stuff). So please check if you have this somewhere. In case you really need it's better to use safe apply (the common code snippet):

angular.module('main', []).service('scopeService', function() {
     return {
         safeApply: function ($scope, fn) {
             var phase = $scope.$root.$$phase;
             if (phase == '$apply' || phase == '$digest') {
                 if (fn && typeof fn === 'function') {
                     fn();
                 }
             } else {
                 $scope.$apply(fn);
             }
         },
     };
});

Then you can inject this service and make necessary calling by:

scopeService.safeApply($rootScope, function() {
    // you code here to apply the changes to the scope
});

这篇关于Angularjs [$ rootScope:inprog] INPROGRESS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆