Until for some reason we need to extend another class and TS doesn't support multiple inheritance. All the other solutions are indeed most used to avoid memory leakage. Also, multiple subscriptions can be also pushed to an array and looped through to unsubscribe from in the ngOnDestoy hook.
The last part at 09:12 is very nice indeed. I really like this kind of work. A great solution for many applications. Once again, great content my friend. 👍
You provide very valuable content, thank you Olexander PS Olexander, consider creating new angular course but even more advanced than medium one - by saying more advanced i mean using bigger spectrum of RxJs operators, change detection strategy, NG rx, using facade pattern, and such tricks like this one with extending abstract class, strict mode, use of firebase? This is just my idea, but knowing your skills as a teacher and experienced developer it would be Very valuable and helpful for developers on any 'level', best regards and stay healthy!
Nice video 👍 I would just like to mention that since version 16, Angular has introduced the "takeUntilDestroyed()" operator, which solves this problem. One question, why did you decorate the parent class "Unsub" with "@Injectable()"? In your example, it is not used as a service provided via dependency injection. Thanks!
I covered takeUntilDestroyed in a separate video ruclips.net/video/ddyxKtfOMqU/видео.htmlsi=i1RHZVQud8YKES4A Yes Unsub doesn't need injectable. It's just a habbit.
Sorry for the dumb question, but what if I have: data$ = interval(1000); const x$ = this.data$.pipe(take(1)); x$.subscribe((data) => console.log('data', data)); Which of the observables does the take(1) operator specifically complete?
Hi, i find this approach very interesting also. DO you might wanna do a short video about that option too. takeUntilDestroyed with destroyRef which close "Automatically" the sub.
Is it correct that we should use ReplaySubject, NOT Subject for unsubscription? After component destroyed it is possible that Subject is destroyed too, but subscription NOT. And subscription survive after destroy. But ReplaySubject can "shot" one more time after component destroy and subscription will be completed.
You can but there is no memory leak is subscribes if you use takeUntil or unsubscribe. Doesn't matter if it is subject, behaivourSubject or replaySubject.
Comission is everywhere -_-. Buying my courses or subscription on the website has the smallest comission and gives you knowledge in return. monsterlessons-academy.com/courses If you don't need a course but just want to support me there is a membership on youtube channel.
@@MonsterlessonsAcademy Okie I am little confused as I am learning angular,should I use vscode or vim? I know it is just IDE but still which has better support?
how would you call abstract unsub class while your component already extends other class? in typescript you cant extend two class. do you have any thoughts about that?
WATCH NEXT: Angular Interview Questions and Answers - Dominate Your Next Interview - ruclips.net/video/5A_YKlVWMPo/видео.htmlsi=2DCn7yspEAAJ2H6l
broo the extended class approach is genius
Thank you!
Until for some reason we need to extend another class and TS doesn't support multiple inheritance.
All the other solutions are indeed most used to avoid memory leakage. Also, multiple subscriptions can be also pushed to an array and looped through to unsubscribe from in the ngOnDestoy hook.
The last part at 09:12 is very nice indeed. I really like this kind of work. A great solution for many applications. Once again, great content my friend. 👍
Thank you very much!
superb explanation of all possible ways of avoiding memory leaks for RxJS subscriptions. Thank you so much ! 🙂
You're welcome!
You are awesome sir,
keep making videos like this !!!
You are teaching a lot of newbies and experienced programmers!!
Thank you, I will
Excellent short and consolidated walkthrough. Thanks for posting.
Glad to hear that!
This channel is underrated.
Thank you!
High quality information as always. Many thanks Oleksandr!
My pleasure!
Thanks!
Thank you so much for your support! It means a lot to me.
Дякую! Дуже круте відео, все чітко і зрозуміло!) Thanks a lot!)
Glad to hear that!
Best and straightforward...but i just see in my navbar one of your videos..
that async pipe is broken in Angular
Yes, you are right
ruclips.net/video/Z9U9-VRN_XU/видео.htmlsi=WUum9t-zTDwQ078W
Amazing post. Maybe you'll make more with RxJS and also with complex Directives. Thank you!
Thank you for the idea!
amazing explanation. super helpful!
Glad it was helpful!
You provide very valuable content, thank you Olexander
PS Olexander, consider creating new angular course but even more advanced than medium one - by saying more advanced i mean using bigger spectrum of RxJs operators, change detection strategy, NG rx, using facade pattern, and such tricks like this one with extending abstract class, strict mode, use of firebase? This is just my idea, but knowing your skills as a teacher and experienced developer it would be Very valuable and helpful for developers on any 'level', best regards and stay healthy!
Thank you for the idea. I will add it to the list of future courses!
Excellent video, I think I'm gonna stick to async pipe and avoid suscriptions, Oninit and Ondestroy altogether in my code...
Yeap. Or look into Signals if you use Angular 16
This is pretty awesome! Love that's it's so easy to implement but so valuable. Thanks!
Glad you like it!
Nice video 👍
I would just like to mention that since version 16, Angular has introduced the "takeUntilDestroyed()" operator, which solves this problem.
One question, why did you decorate the parent class "Unsub" with "@Injectable()"? In your example, it is not used as a service provided via dependency injection.
Thanks!
I covered takeUntilDestroyed in a separate video
ruclips.net/video/ddyxKtfOMqU/видео.htmlsi=i1RHZVQud8YKES4A
Yes Unsub doesn't need injectable. It's just a habbit.
Thank you ! Very useful information !
You are welcome!
Sorry for the dumb question, but what if I have:
data$ = interval(1000);
const x$ = this.data$.pipe(take(1));
x$.subscribe((data) => console.log('data', data));
Which of the observables does the take(1) operator specifically complete?
It's not dumb. x$ is a new observable based on data$. As you subscribe to x$ it has a take function
Brilliant! Thank you.
You're very welcome!
Hi, i find this approach very interesting also. DO you might wanna do a short video about that option too.
takeUntilDestroyed with destroyRef which close "Automatically" the sub.
Hi, I already did that
ruclips.net/video/ddyxKtfOMqU/видео.htmlsi=iAcYmh8rOUI-w6ZX
Many Many Thanks to you sir, You make my day
It's my pleasure
What should we do if we need ngOnDestory in the child component or how we can override it?
override it an call super
Thank for your awesome content
Glad you like it!
Legend! Thanks for the awesome content especially the custom takeUntil(), pretty useful
Glad you like them!
amazing stuff, we need to call super right if we use this class as a common for all components ?
Yes of course
Is this possible way of avoiding super inside constructor
@@chagamajaykumarreddy1897 no, it's how prototypes are working in js
Very nice video man, congrats! Could you make a video talking about the new operator released in Angular 16, the "takeUntilDestroyed()"
Where did you find such method. Can you give a link?
Is it correct that we should use ReplaySubject, NOT Subject for unsubscription?
After component destroyed it is possible that Subject is destroyed too, but subscription NOT. And subscription survive after destroy. But ReplaySubject can "shot" one more time after component destroy and subscription will be completed.
You can but there is no memory leak is subscribes if you use takeUntil or unsubscribe. Doesn't matter if it is subject, behaivourSubject or replaySubject.
Thank you for the good content 🤩
Glad you enjoy it!
I still remember several projects where the people forgot to close subscriptions...
Yeap. Happens all the time.
Hello! I love your video so much. Where is the best place to support you? On your platform or udemy (as far as I know udemy takes some commission)?
Comission is everywhere -_-. Buying my courses or subscription on the website has the smallest comission and gives you knowledge in return.
monsterlessons-academy.com/courses
If you don't need a course but just want to support me there is a membership on youtube channel.
Should i unsubscribe route change as well
Angular does it for us but I prefer to just unsub for every subscribe I see
Hi, can you tell us which IDE you are using? :)
It's Vim
@@MonsterlessonsAcademy Okie I am little confused as I am learning angular,should I use vscode or vim? I know it is just IDE but still which has better support?
@@ArthunMorgan747 You should use vscode and focus on learning programming and not configuring the editor which with vim will take a lot of time.
@@MonsterlessonsAcademy thank you 😁
how would you call abstract unsub class while your component already extends other class? in typescript you cant extend two class. do you have any thoughts about that?
You can't do that. Extend approach is not that popular in Angular at all. Typically you just inject services and use them.
Awesome content on unsubscribe
Happy to hear that!
you'll need a super() call in the component's constructor using / extending this class, otherwise TS will complain?
You are totally right. If you need to do anything in contructor you must call super.
You re the best! Tnxx!
Thank you!
Premium content, useful information. Thank you
Glad it was helpful!
Wait what? I was sure the component is destroy when not in the view anymore and by consequence all subscribe are unsubscribed…
Destroying doesn't have anything to do with the in view or not. Also you need to unsubscribe manually.
why don't we just use a promise for queries? this sounds like a potential problem in your app to troubleshoot.
It's architecture of Angular team. I didn't have any problems or need to use promises in Angular.
Крутотень)
Monster! 😂
I don’t feel like the video is useful at all, this can be found in angular doc and this is far from real life situation (interval really ? ..)
It's the example to see that stream was canceled.
Last one approach is nice but it does not allow to use "ngOnDestroy" in the "Postscomponent" as it is already declared in "Unsub".
but we can add "public unsubscribe(): void {" in "Unsub" and call it from "public override ngOnDestroy() {", "this.unsubscribe();" to solve it.
exactly