Skip to content

Conversation

@danielcrisp
Copy link

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.

rike422 added a commit to rike422/angular-unsavedChanges that referenced this pull request Aug 22, 2016
Prevent $digest already in progress error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant