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
Create ngProgress $http interceptor #10
Comments
I will have a look on how you can use ngProgress with $http interceptor but I have not used any interceptors yet so will probably take some time. |
Hey Alari, Here's how we did it in a project: (1) Create a separate service (call it progressService.) Sort of like this: |
@selfinterest looks simple in implementation and fitting the need, but there's an overhead with emitting and catching events (well, not really heavy). Haven't you tried to pass I will play with your suggestion on our beta, thank you! :) |
Okay, I went back and thought through the issue some more. The problem was, trying to inject ngProgress into the factory function was giving me a circular dependency error. I did some checking and found this: Using that as a model, I came up with this: http://plnkr.co/2CxGZ5fBg6BTfalpeBnb It seems to do the job, without the extra service or using events. Hope this helps! |
I just implemented. It sort of works but it seems that the ngProgress bar gets a bit confused sometimes and starts animating all over the place! Might be a few bugs to debug in it, I'll take a look. |
We've had some issues with that. It seems to occur when multiple http requests go out in quick succession (which can easily happen, especially in a single page app.) I've been thinking of a few ways to deal with that: (1) Simplest way: set a flag in the interceptor when the progress bar starts. Switch the flag off when the response comes in. If the flag is set, don't start the progress bar again. (2) Some kind of queue system, where you start progress bars sequentially as soon as one finishes. That seems like a bit of overkill to me, but could probably be done. I haven't dug too much into @victorbjelkholm's code. The circular reference problem in the interceptor happened to me a second time, using an unrelated module (the $modal from angular-ui-bootstrap, actually.) So it has less to do with ngProgress and more to do with the relationship between $http and $compile. I had to use the same solution in that case, lazily loading the $modal service. In that case, I went with option (1), because I didn't want multiple modal windows popping up for each failed request. It seemed to work okay in that case. |
Just added the flag system and it works great. This has actually been a good lesson on using the injector service in interceptors as I'd also tried to use the $modal service from AngularUI for error responses and given up. |
I still had a few issues with the script above and it uses the depreciated reponseInterceptor instead of the generic http interceptor. This updated code only displays the ngProgress for loading non templateUrl http requests too.
|
Here's the above code snippet translated to JS:
|
Hi Victor.
I saw your great ngProgress bar and wished to switch to it from my ugly spinner loader.
Usually I use $http interceptor, like in the following code:
Sure, it doesn't work.
Also it looks like it is the most simple plain case to use ngProgress, probably it worth to add some function to its api.
The text was updated successfully, but these errors were encountered: