Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : $digest already in progress when using two Http request calls in same angular Js function

i'm aware of $digest already in progress error issue, but here i'am not calling the apply or digest method explicitly

I'm using two http calls in same angularJS function which leads me to the Error that $digest already in progress, My code is like

 $http.post('/CRUDOper/memberInsert',$scope.memberAdd).
        success(function(post){
            if(!post.IsSuccess){
                alert(post.msg + "Try Again");
                return;
            }
            alert("Member Added Successfully");
        }
    );

    var autopass = Math.random().toString(36).slice(-8);
    var passwordinsert = {formno : $scope.memberAdd.formno, password : autopass  };
    $http.post('/CRUDOper/autogeneratepassword',passwordinsert).
        success(function(post){
            if(!post.IsSuccess){
                alert(post.msg + "Try Again");
                return;
            }
            alert("Autogenerated Password for present user : " + autopass );
        }
    );

both the request are called correctly what my concern is the error in the firebug that $digest already in progress is there any way i can handle this error ?

like image 666
Vinod Louis Avatar asked Nov 12 '22 01:11

Vinod Louis


1 Answers

AngularJS' event loop does not wait until alert(), confirm(), and prompt() return a value (at least for $http calls). There is, however, a short interval between rendering the popup and entering into the $digest loop. This explains why OP did not get the error the first time: OP clicked or pressed return very soon.

To verify for yourself that this does not depend on the number of http calls, try using one alert in the success() method of a single http call. There will be no error if you confirm the popup within approx. 300ms, but there will be an error if you confirm it at a later time.

like image 183
AliOli Avatar answered Nov 14 '22 22:11

AliOli