Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag'n'drop - Error: $digest already in progress #65

Closed
tihomir-kit opened this issue Nov 30, 2013 · 4 comments
Closed

Drag'n'drop - Error: $digest already in progress #65

tihomir-kit opened this issue Nov 30, 2013 · 4 comments

Comments

@tihomir-kit
Copy link

Hi,

I wanted to wrap your angular-file-upload directive within my own directive, and it works fine except the drag'n'drop area. The error I'm getting when the drag'n'drop input is inside my directives view template is: "$digest already in progress" (angular-file-upload.js ln.117).

scope.$apply(function() {

I did a bit of research and found this SO article.

Basically, adding $timeout to 'ngFileDropAvailable' fixed the issue. This is the original method:

angularFileUpload.directive('ngFileDropAvailable', [ '$parse', '$http', function($parse, $http) {
    return function(scope, elem, attr) {
        if ('draggable' in document.createElement('span')) {
            var fn = $parse(attr['ngFileDropAvailable']);
            if(!scope.$$phase) {
                scope.$apply(function() {
                    fn(scope);
                });
            } else {
                fn(scope)
            }
        }
    };
} ]);

and this is the fixed one:

angularFileUpload.directive('ngFileDropAvailable', ['$parse', '$http', '$timeout', function ($parse, $http, $timeout) {
    return function (scope, elem, attr) {
        if ('draggable' in document.createElement('span')) {
            var fn = $parse(attr['ngFileDropAvailable']);
            if (!scope.$$phase) {
                $timeout(function () {
                    scope.$apply(function () {
                        fn(scope);
                    });
                });
            } else {
                fn(scope)
            }
        }
    };
}]);

My project is on v1.0.7 of angular, so perhaps that's why I'm getting this error, but I believe $timeout shouldn't break anything for newer versions of angular either if implemented into your directive. So perhaps you could add the timeout fix to patch this up? I could also submit this as a patch.

Thnx :)

@danialfarid
Copy link
Owner

Could you please verify if this would fix the issue instead of timeout:

if ('draggable' in document.createElement('span')) {
    $parse(attr['ngFileDropAvailable'])(scope);
    if(!scope.$$phase) {
        scope.$apply()
    }
}

@tihomir-kit
Copy link
Author

Sure, I'll check it out tomorrow morning and then I'll get back to you. Thnx for the reply.

@tihomir-kit
Copy link
Author

Hi, your fix does show the drag'n'drop area, but the console still shows the $digest error.

@danialfarid
Copy link
Owner

I fixed the $scope.$apply issues at 1.1.10

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

No branches or pull requests

2 participants