How to use the ASYNC PIPE effectively in Angular Templates

  Рет қаралды 37,942

Joshua Morony

Joshua Morony

Күн бұрын

Пікірлер: 55
@AlanMontgomery
@AlanMontgomery 3 жыл бұрын
The amount of angular stuff I've learned (by accident haha) by watching your intriguing videos Josh is crazy! I used Angular for about a year only before! Nice vid!
@JoshuaMorony
@JoshuaMorony 3 жыл бұрын
Haha thanks! Careful man, or you'll be joining the red side before you know it
@leonardopillay4200
@leonardopillay4200 3 жыл бұрын
Where have you been all my life? I love how detailed you are with your explanations.
@yekaterinacrawford2037
@yekaterinacrawford2037 2 жыл бұрын
Josh, this is one of the best videos on Obesrvables and Angular I've watched in a long time (or maybe ever)! Real life example (not just setTimeout or a timer), very CLEAR explanation. THANK YOU a thousand times! I've subscribed to your channel and promise to go and like every single video on your channel.
@manassrivastava6452
@manassrivastava6452 Жыл бұрын
Best Angular Tutorials out there on KZbin
@markvanmameren
@markvanmameren Жыл бұрын
One of the best Angular KZbin channels out there 👏🏻
@janeywebdev2370
@janeywebdev2370 Жыл бұрын
I am thrilled by your videos Josh! I ran into them via playlist suggestion and I am so happy I did! The best, concise, comprehendible explanations by far!!! Thank you for sharing your knowledge and experience. It's been a huge help!
@jamienordmeyer4345
@jamienordmeyer4345 2 жыл бұрын
I wasn't aware of the `;else loading` functionality. Learned something new yet again. Thanks Josh!!!
@ChristopherRobertHarris
@ChristopherRobertHarris 3 жыл бұрын
Thanks, Josh. I’ve used async pipe as in your first example but never realised you could do all the other stuff. Very informative video, cheers.
@samclavette420
@samclavette420 2 жыл бұрын
So happy to see this syntax for subscribing to an observable that returns an object!
@Rani.Dutta.
@Rani.Dutta. Жыл бұрын
I watched so many videos on async pipe, and finally I am able to resolve the error of my code. No one explains the part where multiple arrays are coming from the backend and how to async a particular array. Thank you so much for this video sir. I'm new to async and was stuck in async part for 3 days straight.
@scottc7909
@scottc7909 Жыл бұрын
I can't believe I didn't watch this video a year ago, it could have saved me a bunch of headaches
@diehypotenuse4908
@diehypotenuse4908 2 жыл бұрын
holy moly, that was clean.
@gusgonnet
@gusgonnet 3 жыл бұрын
great tips Josh, thank you!
@rgablejr
@rgablejr Жыл бұрын
Thank you! Great content!
@miyasmohammed4342
@miyasmohammed4342 3 жыл бұрын
wow, nice its a very much informative video for angular or ionic developers.
@sunantjong8463
@sunantjong8463 3 жыл бұрын
Great tips Josh :) very useful tips
@jaybee6382
@jaybee6382 Жыл бұрын
ngrxLet* is also a less verbose way of doing this. Great video.
@md.habiburrahman7834
@md.habiburrahman7834 Жыл бұрын
Thanks Joshua.
@nagendradevara1
@nagendradevara1 3 жыл бұрын
Thank you , will try to incorporate it.
@penumono
@penumono Жыл бұрын
Hi Josh. Could you make a video of using async pipe for crud operations in a table in angular?
@trustingod0
@trustingod0 2 жыл бұрын
Great Information. I was just wondering what do you mean when you said await a result? Thanks !!!
@tomcatbuzz
@tomcatbuzz 3 жыл бұрын
Great video. Would the concept be the same for the *ngFor="let client of clients | async"? For showing a loader when the clients list is loading.
@TravisSomaroo
@TravisSomaroo 2 жыл бұрын
Thanks Josh! I have been watching a lot of your videos recently, extremely valuable content. I wanted to ask if there was a repo we could access to view the source code of your vids. Thanks for everything!
@JoshuaMorony
@JoshuaMorony 2 жыл бұрын
Hey Travis - check the description on the vids, any videos where I have the source code available will have a link in the description
@flesa969
@flesa969 2 жыл бұрын
@Joshua Morony What if you have multiple obersables? How to combine them to one?
@samnickliboum9857
@samnickliboum9857 3 жыл бұрын
Hi Josh. What impressive work you are doing! I would like to know whether you have a tutorial showing how to upload pictures (camera & library) in firebase storage using th new version of firebase SDK. thank you again for all
@michelletao5872
@michelletao5872 Жыл бұрын
For the second example, why did you use a div tag instead of ng-container?
@pekahon
@pekahon 2 жыл бұрын
but...one important example is always missing in async.. How to subscribe data with async pipe from service witch requires parameters, like user id or similar?
@JacinLowe
@JacinLowe 2 жыл бұрын
like dependency injection? or you could create a stream to get the data then switch map to your service observable with that user id data. i.e of().pipe(#wait for emmision#, switchMap((user.id) => return service.observable(user.id))). or something like that.
@alex25197
@alex25197 Жыл бұрын
What if I would like to display a message of “no client found” if the http request returns empty? How does the async pipe knows that is not loading but finished loading and returning empty values?
@MichaelSalo
@MichaelSalo 2 жыл бұрын
Does the expression "let client of client$ | async" get interpreted as "(let client of client$) | async" or "let client of (client$ | async)" ? In other words what is the precedence of the pipe?
@JoshuaMorony
@JoshuaMorony 2 жыл бұрын
This isn't really something I have thought about, but *ngFor only works with iterable objects like arrays, so "let client of client$" wouldn't work as an observable stream is not iterable, but (client$ | async) will pull the iterable value out of the stream to be looped over. So, "let client of (client$ | async)" I guess would be the right way to think of it.
@MichaelSalo
@MichaelSalo 2 жыл бұрын
@@JoshuaMorony Thanks for this clarification
@juanpabotero
@juanpabotero 2 жыл бұрын
Hi! Can I use the Async pipe with the method trackBy using *ngFor, ex: *mgFor="let client of clients$ | async; trackBy: trackByFn"
@Eltopshottah
@Eltopshottah 2 жыл бұрын
Thank you!
@leonardopillay4200
@leonardopillay4200 2 жыл бұрын
Hi Joshua, I have been facing an issue that I have no explanation for. I have been trying to implement your approach to the async pipe where the parent calls the async pipe and injects the data into the child component. The issue I'm facing is that any lazy loaded pages don't trigger change detection and I'm stuck with the loading template until I either refresh the page or resize the browser window. I've tried every strategy with the angular change detection even as far as checking for changes manually. Let me explain a bit more about what's happening. I log in with firebase after login i get the current logged in user and switch map to fetch that user profile. I then use the user's data to retrieve the company that use user belongs to. when visiting lazy loaded pages after initial login in I'm stuck with the loading template as change detection does not happen.
@lcho9871
@lcho9871 2 жыл бұрын
Excellant and thanks.
@CodingAbroad
@CodingAbroad 3 жыл бұрын
So it’s mostly good to use providing you don’t need to change the data? In which case you’d stick with subscription
@JoshuaMorony
@JoshuaMorony 3 жыл бұрын
Changing the data is fine, it's when you need to access data from the stream inside if your components class that you might have to subscribe manually.
@CodingAbroad
@CodingAbroad 3 жыл бұрын
@@JoshuaMorony thanks for the info. If you were populating a reactive form with values obtained from an http get request then I guess you would have to use subscription because you can’t use async in the template
@JoshuaMorony
@JoshuaMorony 3 жыл бұрын
​@@CodingAbroad Yes that's a good example of where you might have to subscribe. Although, you could also structure it to still use the async pipe, it would just be a bit more complex. If you had your form inside of a child component, you could use the async pipe in your parent component template, and then pass the form values in to the child component. Then your child component can just react to changes in input, and you never have to manually subscribe to the observable.
@kush.mikashita
@kush.mikashita 3 жыл бұрын
Hummm... this is good. Thanks
@ksivasuriyaprakash9976
@ksivasuriyaprakash9976 3 жыл бұрын
Nice!
@Matrium0
@Matrium0 2 жыл бұрын
Great video. You (like almost everyone about async) did skip the ugly parts though - error handling! Doing that in a fully reactive way does gut ugly to the point where you start questioning your usage of async altogether :(
@JoshuaMorony
@JoshuaMorony 2 жыл бұрын
I have a separate video on handling errors reactively with the async pipe (in a non-ugly way, at least I think so): kzbin.info/www/bejne/oZOcdHWaZ8hnq6M
@Matrium0
@Matrium0 2 жыл бұрын
@@JoshuaMorony Oh, nice, awesome!
@joelv6886
@joelv6886 2 жыл бұрын
Heres how cool async pipes are. Lets not show them error handling or updating the stream because... It's ugly.
@JoshuaMorony
@JoshuaMorony 2 жыл бұрын
Is there a particular scenario you want to see covered? With a reactive approach there isn't really any issue with errors, you would generally just have another stream for your error state. So for this example we could extend it by adding an additional element inside of the loading container that uses the async pipe to subscribe to the error stream. Now the loading container will display when client$ hasn't emitted (we could use pipe to catch errors from the client$ stream and cause the error stream to emit), and the reason for that will either be because there was an error or just because it hasn't finished loading yet.
@michaelharrington5860
@michaelharrington5860 Жыл бұрын
This is the problem with tutorials. People show half the information and expect viewers to know the other half already. Show the rest of the code
@tailofahippopotamus9775
@tailofahippopotamus9775 2 жыл бұрын
Pretty neat thing I've found out recently when you need to organize multiple subscriptions in the template: Wrap your template code in an ng-container and an object like so *ngIf="{ observable1: observable1$ | async, observable2: observable2$ | async } as data" Now you can access it like this in the template (within the ng-container): data.observable1
@sergiohidekiono771
@sergiohidekiono771 2 жыл бұрын
I like the way you explain! I have a question, for example if in the returns of some endpoint has another url to request another get nested with more detailed information, how can I handle with | async? Or should I handle with manual observable? For example: (get) /heroes/1: name: "Batman", url: "..../batman/1" (get) /batman/1: img: "..../1.jpg, height: 6 feet, 2 inches tall etc...
@JoshuaMorony
@JoshuaMorony 2 жыл бұрын
You can do all of this with a single stream and subscribe with the async pipe - You would create a stream for the first request, and then use the pipe method to add on one of the higher order observable operators (e.g. switchMap, concatMap, mergeMap, exhaustMap) - these all do slightly different things based on the exact behaviour you want. But in this case, you probably want to use switchMap to take the batman value from the first stream, and then switchMap to a second http stream using the batman value in the request.
How to share your RxJS observables for improved performance
10:24
Joshua Morony
Рет қаралды 24 М.
Why use OnPush in Angular? Not for performance...
13:16
Joshua Morony
Рет қаралды 32 М.
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 15 МЛН
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 7 МЛН
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 51 МЛН
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 59 МЛН
Angular unsubscribe, Angular async pipe, RxJS subscribe - Avoid Memory Leaks
11:29
The hidden gotcha with async in Angular forms
10:37
Joshua Morony
Рет қаралды 18 М.
💥Angular Mistakes #1: ✋ DON'T Overuse the Async Pipe  #angular
7:15
Angular University
Рет қаралды 7 М.
ngTemplateOutlet is WAY more useful than I realised
16:36
Joshua Morony
Рет қаралды 77 М.
💥 Angular Async Pipe - Learn the Main Advantages
4:09
Angular University
Рет қаралды 40 М.
The easier way to code Angular apps
9:54
Joshua Morony
Рет қаралды 69 М.
Why I use a view model stream for my Angular templates
15:11
Joshua Morony
Рет қаралды 33 М.
I only ever use *these* RxJS operators to code reactively
25:25
Joshua Morony
Рет қаралды 136 М.
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 15 МЛН