Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Extent-change listener generates "$digest already in progress" #313

Closed
CloudCees opened this issue Nov 8, 2016 · 4 comments
Closed

Extent-change listener generates "$digest already in progress" #313

CloudCees opened this issue Nov 8, 2016 · 4 comments
Assignees
Labels

Comments

@CloudCees
Copy link

CloudCees commented Nov 8, 2016

We are using the v1 directives

Expected behavior

No errors in Console.

Actual behavior

Map.setExtent() sometimes generates the error as mentioned in the subject. I expect that when the extent is set it will not generate this error.

  • Provide any error messages you see in the console.
    "$digest already in progress"

Steps to reproduce the behavior

In the link below:

  • Open the browser's console
  • Press multiple time on the button 'set extent' until the error in the console appears.

https://embed.plnkr.co/6C7GsTibHykPJQcxeU2g/

For us working solution:

In esri code below, scope.$apply() is causing this error. When we change $apply to $evalAsync the error isn't appearing anymore.

map.on('extent-change', function(e) {
    if (attrs.extentChange) {
        self.extentChange()(e);
    }
    // prevent circular updates between $watch and $apply
    if (self.inUpdateCycle) {
        return;
    }
    self.inUpdateCycle = true;
    scope.$apply(function () {
        // update scope properties
        updateCenterAndZoom(self, map);
        $timeout(function() {
            // this will be executed after the $digest cycle
            self.inUpdateCycle = false;
        }, 0);
    });
});

For more information about $evalAsync:
http://stackoverflow.com/questions/12729122/angularjs-prevent-error-digest-already-in-progress-when-calling-scope-apply/23102223#23102223

With kind regards

@jwasilgeo jwasilgeo added the bug label Nov 8, 2016
@jwasilgeo jwasilgeo self-assigned this Nov 8, 2016
@jwasilgeo
Copy link
Contributor

@Cezus thanks for bringing this to our attention. I have looked into it and will continue to investigate and test between using $evalAsync and $applyAsync.

As a side note in your plnkr, (and thanks for providing a reproduction case), I would also advise not to call esriLoader.require every time your button click handler function is entered. You could call esriLoader.require once at the beginning of your controller scope and set the imported modules to scope properties, for example, that you can reference in your button click handler. Just a suggestion in case you are doing this in your other applications.

@CloudCees
Copy link
Author

CloudCees commented Nov 8, 2016

@jwasilgeo Great! Thank you for the fast response.

"I would also advise not to call esriLoader.require every time your button click handler function is entered."
Thank you for the headsup, the plunker was a fast write.

@jwasilgeo
Copy link
Contributor

@Cezus sorry for the delay. I hope to have a fix (and new release version) for this sometime soon. Hopefully you've been able to continue on your own in the meantime?

jwasilgeo pushed a commit that referenced this issue Dec 23, 2016
- updated npm dev dep versions to be able to run gulp test
- formatting update on test/set-center-zoom.html
@jwasilgeo
Copy link
Contributor

fixed in PR #315 and the fixed code is available on the v1 branch (an upcoming release will also include this fix)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants