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

Use $q for the upload service #46

Closed
dominicglenn opened this issue Nov 14, 2013 · 5 comments
Closed

Use $q for the upload service #46

dominicglenn opened this issue Nov 14, 2013 · 5 comments

Comments

@dominicglenn
Copy link

It would be good if the library returned it's own deferred instead of $http's. This would allow it to also use $q's notify() method to update the progress of the upload instead of having it as a passed option which requires a $apply to do stuff to the scope?

Hope this is clear.

@danialfarid
Copy link
Owner

There is no easy way to attach the progress listener to the angular's XmlHttpRequest after it is send that's why it needs to be part of options.
Basically the shim that is loaded before angular will override the XmlHttpRequest to get access to it when angular is using it since angular uses a private instance of it and won't provide any mean to access xhr. When angular calls the xhr.send() I attach the progress listener to it. You can have a look at the code to see if you can find an alternative way. If you have any questions about it ask here.

danialfarid added a commit that referenced this issue Nov 15, 2013
@danialfarid
Copy link
Owner

Ok I found a workaround. This should be fixed now you don't need to call $scope.$apply() and you can just listen to the progress event with .then(success, error, progress) or .progress()

@dominicglenn
Copy link
Author

You should be aware that using the .notify() method on the $q deferred means that you need at least angular 1.2

I was using 1.0.8 and the $q on that doesn't support that method.

@danialfarid
Copy link
Owner

It is optional if you don't want to use notify just put the progress as an option or call .progress() on the returned promise for 1.0.8

@dominicglenn
Copy link
Author

Ah right, okay. Thanks.

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