Add an Angular Loading Spinner with RxJS and Material

  Рет қаралды 18,458

Zoaib Khan

Zoaib Khan

Күн бұрын

#Angular #Loading #Spinner #rxjs
Want to learn how to create a full stack application with Angular and Firebase?
Grab my new course 'Angular Firebase Authentication: Create Full Sign up App' with 50% off here:
www.udemy.com/...
In this video, I show you how to add an Angular Loading Spinner with RxJS and automatically make it appear whenever there is a network call by using HttpInterceptor.
The complete code for this tutorial can be found here:
github.com/thi...
Follow me on:
Twitter - / zoaibdev
Facebook - / thisiszoaib
LinkedIn - / zoaib-khan-b6456815
And check out my blog at zoaibkhan.com!
Cheers :)

Пікірлер: 40
@ZoaibKhan
@ZoaibKhan 2 жыл бұрын
Hey guys! Check out the follow up video to this tutorial on the link below. I cover some improvements especially related to making multiple calls and their issues with the spinner kzbin.info/www/bejne/imnXd4ZsqZili9k
@TheFilburt88
@TheFilburt88 2 жыл бұрын
This is one of the best tutorials I've seen so far, you explained it very well. Thank you so Much!
@ZoaibKhan
@ZoaibKhan 2 жыл бұрын
You're very welcome, Franco! Glad it has helped in some way :)
@karthiksadanand5578
@karthiksadanand5578 2 жыл бұрын
This is one of the cleanest tutorials !, thank you
@ZoaibKhan
@ZoaibKhan 2 жыл бұрын
Thanks Karthik, glad you liked it!
@MariaBadanina
@MariaBadanina 5 ай бұрын
Thank you very much! This video helped me
@ZoaibKhan
@ZoaibKhan 5 ай бұрын
Glad you liked it!
@emmanuellatrustenomah532
@emmanuellatrustenomah532 10 ай бұрын
This was very helpful!
@ZoaibKhan
@ZoaibKhan 10 ай бұрын
Glad you liked it! 👍
@plumemotorpartpmp1625
@plumemotorpartpmp1625 2 жыл бұрын
thank you teacher very good lesson : )
@ZoaibKhan
@ZoaibKhan 2 жыл бұрын
You're welcome :)
@alexou857
@alexou857 2 жыл бұрын
Thank you my man, you are the best :)
@ZoaibKhan
@ZoaibKhan 2 жыл бұрын
You're welcome. Glad you liked it :)
@amalrajp83
@amalrajp83 3 жыл бұрын
Hi Useful video👍. One qn , Will this work properly if multiple calls are done at same time?
@ZoaibKhan
@ZoaibKhan 3 жыл бұрын
Hey Amal! Good question :) The answer is no. To allow multiple calls at same time, we'll need to increment and decrement a counter on start and end of API calls in the interceptor. Then, only hide the spinner when counter is 0 i.e. no calls are in process. Hope that helps
@amalrajp83
@amalrajp83 3 жыл бұрын
@@ZoaibKhan Thanks for the repy
@gradientO
@gradientO 3 жыл бұрын
Good tutorial
@ZoaibKhan
@ZoaibKhan 3 жыл бұрын
Thanks!
@giorgimerabishvili8194
@giorgimerabishvili8194 3 жыл бұрын
Thank you!
@ZoaibKhan
@ZoaibKhan 3 жыл бұрын
Welcome, Giorgi!
@raviteja8798
@raviteja8798 2 жыл бұрын
Hello sir, I have one doubt regarding this. please help me sir, please reply
@ZoaibKhan
@ZoaibKhan 2 жыл бұрын
What kind of doubt, jhon?
@ZoaibKhan
@ZoaibKhan 2 жыл бұрын
@@raviteja8798 here's the follow up video to this tutorial which covers and fixes this issue. Hope it helps! :) kzbin.info/www/bejne/imnXd4ZsqZili9k
@ZoaibKhan
@ZoaibKhan 2 жыл бұрын
@@raviteja8798 ok, let me go through your problem in detail and see what the issue might be
@ZoaibKhan
@ZoaibKhan 2 жыл бұрын
@@raviteja8798 Hey! So after going your message in detail, it seems your problem is with the long-running API call on Component A. Ideally, you should add a way for the API call to be cancelled once the user navigates away from the component - because it's no longer needed. Here's a link for a possible solution: www.freakyjolly.com/angular-how-to-cancel-http-calls-on-router-change/ If you do need the data from the API call - then maybe you should use a global service with another behavior subject and load it there and add an exception in the interceptor - where the spinner doesn't show for this specific call. I'd suggest though to review this 1 minute long API call - because it would be pretty bad for user experience, besides creating this spinner problem... Hope this helps.
@kiendinhkhoi
@kiendinhkhoi 3 жыл бұрын
How to show spinner and blur background bro?
@tranquillityEnthusiast
@tranquillityEnthusiast 3 жыл бұрын
Need more vedios..
@vuduyanh7791
@vuduyanh7791 3 жыл бұрын
thank you so much , if settimeout for loading Spinner , what i do , please support
@ZoaibKhan
@ZoaibKhan 3 жыл бұрын
You're welcome, Vu! Can you describe in more detail, why do you want the settimeout for the loading spinner?
@vuduyanh7791
@vuduyanh7791 3 жыл бұрын
@@ZoaibKhan tks your , i do it success , However , I'm getting an error NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'false'. Current value: 'true'.. your can help me .
@ZoaibKhan
@ZoaibKhan 3 жыл бұрын
Yes, this just appears in development and does not really affect the functionality much. But still, you can make a small change in the service on this line: loading$ = this._loading.asObservable().pipe(delay(1)); This is similar to setTimeout - using the RxJS delay operator instead because it looked cleaner to me. This should clear the error in development.
@vuduyanh7791
@vuduyanh7791 3 жыл бұрын
@@ZoaibKhan thanks your so much
@ZoaibKhan
@ZoaibKhan 3 жыл бұрын
@@vuduyanh7791 you're welcome :)
@AGGPEE
@AGGPEE 2 жыл бұрын
Oh me vengoooo
@rohitsoni2439
@rohitsoni2439 2 жыл бұрын
Those who are facing error expression changed please add this : public readonly loading$ = this._loading.asObservable().pipe(delay(1));
@ZoaibKhan
@ZoaibKhan 2 жыл бұрын
Thanks for the public service message Rohit!
@JamesMoore-zg9ue
@JamesMoore-zg9ue 3 жыл бұрын
I get the following error message. NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'false'. Current value: 'true'.. This is something to do with the loading$ variable in my app.component.html. Just wondering if anyone knows a fix for this.
@ZoaibKhan
@ZoaibKhan 3 жыл бұрын
Hey James! It is a development time error only and the quickest fix for it will be to add a small delay so that the the loading value is updated in the next change detection cycle. If you look at the latest code (link in description), I've already fixed that there. Hope that helps!
@ogunkayodeoluwaseun9348
@ogunkayodeoluwaseun9348 Жыл бұрын
@@ZoaibKhan how does one add this delay??? cause I'm facing the same error
@ZoaibKhan
@ZoaibKhan Жыл бұрын
@@ogunkayodeoluwaseun9348 Check out the code in the description!
RxJS in Angular: Terms, Tips, and Patterns
43:01
Deborah Kurata
Рет қаралды 31 М.
РОДИТЕЛИ НА ШКОЛЬНОМ ПРАЗДНИКЕ
01:00
SIDELNIKOVVV
Рет қаралды 3,6 МЛН
小天使和小丑太会演了!#小丑#天使#家庭#搞笑
00:25
家庭搞笑日记
Рет қаралды 52 МЛН
Стойкость Фёдора поразила всех!
00:58
МИНУС БАЛЛ
Рет қаралды 6 МЛН
How do Cats Eat Watermelon? 🍉
00:21
One More
Рет қаралды 13 МЛН
Easy, Dynamic Angular Material Theming with just 6 colors!
20:26
Loading indicator done right | Angular Tips and Tricks
17:51
Code With Gio
Рет қаралды 7 М.
RxJS, the easy way to write correct Angular applications
53:07
Oasis Digital
Рет қаралды 43 М.
Hot vs Cold Observable in RxJs (2021)
15:06
Decoded Frontend
Рет қаралды 27 М.
What’s new in Angular v18
20:08
Angular
Рет қаралды 128 М.
РОДИТЕЛИ НА ШКОЛЬНОМ ПРАЗДНИКЕ
01:00
SIDELNIKOVVV
Рет қаралды 3,6 МЛН