angular-unsavedChanges icon indicating copy to clipboard operation
angular-unsavedChanges copied to clipboard

Prevent $digest already in progress error

Open danielcrisp opened this issue 8 years ago • 0 comments

I had an edge-case issue where the confirm popup was blocking my JS thread mid-digest and I was getting an error in IE11.

It happened when clicking a button with ng-click to trigger navigation / state change.

Wrapping this in a setTimeout did the trick

    // allow any existing scope digest to complete
    setTimeout(function () {
        if (!confirm(unsavedWarningsConfig.navigateMessage)) {
            unsavedWarningsConfig.log("user wants to cancel leaving");
            event.preventDefault(); // user clicks cancel, wants to stay on page
        } else {
            unsavedWarningsConfig.log("user doesn't care about loosing stuff");
            $rootScope.$broadcast('resetResettables');
        }
    });

Also I change the scope.$apply used in the unsavedWarningForm directive for a $timeout which is safer.

danielcrisp avatar Sep 17 '15 18:09 danielcrisp