I just inadvertently learned this a few days ago. I agree, this inject() method is preferable for several reasons. 1) it visually states exactly what is happening and makes it clear it was intended. 2) it de-clutters the constructor() method which may be required for other tasks like passing in a data structure housing strings a component needs for display like a modal dialog. 3) eliminates the mystery about how the compiler figured out how to CALL the constructor with the extra parameter and why the order of parameters doesn't matter.
Insanely good explanation! I hesitated dropping constructors injection because I didn't feel the real need to move to inject() But I didn't know it is possible to export destroy$ for example in a simple reusable function
Note that you don't need a clever hand-rolled helper like that any more since Angular 16 because it has that built in now - its takeUntilDestoyed() / DestroyRef
That is a really clever implementation of the old takeUntil pattern :) I wonder if Angular 16, think came out just a few months after this video, blatantly stole your idea when introducing DestroyRef :-D
Good video ! do you have a video about OnChange and how can i use it between parent and child component so i dont have to reload the page to view changes ?
It's a very good video, thank you! I wonder if it would be better to name functions that can only be used in an injection context in a specific way, in order to differentiate them from other functions. For example I would prefer to call them "injectPageParam()" or "injectOnDestroy()".
Don't know why Angular is bringing so many things at once..Really hard to get clear idea in Mind What to use and When to use. Confusion hi Confusion hai😅😅
At least almost all of the new things help make it suck less. The main pain point of Angular has always been way too much boilerplate and needless complexity, and I'm happy to see that with every release they are trying really hard to reduce that.
@@cod3r1337 After working in Angular with over a year, I can conclude Angular is the worst framework I have ever used. It's documentation is the worst. Even Angular Material's documentation is worst. They both doesn't mention when to use which things. They just mention definitions with good CSS in their website. All the things needs to be find out by Developer itself. 🤬🤬🤬
WATCH NEXT: Angular Interview Questions and Answers - Dominate Your Next Interview - ua-cam.com/video/5A_YKlVWMPo/v-deo.htmlsi=2DCn7yspEAAJ2H6l
Wow there are so many things to learn in Angular...
Yeap. Unfortunately they don't want to stop.
I just inadvertently learned this a few days ago. I agree, this inject() method is preferable for several reasons. 1) it visually states exactly what is happening and makes it clear it was intended. 2) it de-clutters the constructor() method which may be required for other tasks like passing in a data structure housing strings a component needs for display like a modal dialog. 3) eliminates the mystery about how the compiler figured out how to CALL the constructor with the extra parameter and why the order of parameters doesn't matter.
Yeap
You are awesome.. you explain in very easy and practical manner.
Thank you
You are welcome!
Insanely good explanation!
I hesitated dropping constructors injection because I didn't feel the real need to move to inject()
But I didn't know it is possible to export destroy$ for example in a simple reusable function
Yeap!
Awesome explanation and moreover, your English is so clear that I wanna listen to you and listen.. Keep going!
Thank you! 😃
Отличная подача! Как всегда материал на высоте
That was really good - both creating re-usable code outside your component and a much cleaner way of extending components. Thanks very much.
You're welcome!
nice video, now i need to refactor all my codes 😁😁
Go for it!
Amazing explanation.
Glad you think so!
Many thanks, great video as always.
Glad you enjoyed it
Awesomely helpful! Thank u
You're welcome!
For the final part what is the advantage of using that over ngOndestroy
You make a reusable function which should not be duplicated in every single component with ngOnDestroy
@MonsterlessonsAcademy Thanks that was very useful information
Note that you don't need a clever hand-rolled helper like that any more since Angular 16 because it has that built in now - its takeUntilDestoyed() / DestroyRef
Amazing content, thanks a lot
My pleasure!
Great Video! What font and theme are you using here? Very readable
It's gruvbox and monaco font.
That is a really clever implementation of the old takeUntil pattern :)
I wonder if Angular 16, think came out just a few months after this video, blatantly stole your idea when introducing DestroyRef :-D
It's not my idea. I also stole it :D
Good video ! do you have a video about OnChange and how can i use it between parent and child component so i dont have to reload the page to view changes ?
I don't have a specific video about OnChange
Please make it one@@MonsterlessonsAcademy
Your courses are short and sweet ❤. Can you please create a new session for unit testing inject() function
I added it to the list of future videos. Thank you for the idea!
@@MonsterlessonsAcademy Would really like this too. Especially where you've extracted them into functions
Does this method of injection protect against creating multiple instances of a service you intend to be a singleton?
It doesn't protect against anything. It is just the same like defining it in the constructor
It's a very good video, thank you! I wonder if it would be better to name functions that can only be used in an injection context in a specific way, in order to differentiate them from other functions. For example I would prefer to call them "injectPageParam()" or "injectOnDestroy()".
There are no guidelines. Maybe we get eslint rules at some point.
How do we mock them in the tests now? Ta
The same way we have always done since Angular 2: Using TestBed.
After 1 year I am knowing it😅
Awesome!
For destroy/unsubscribe we can use takeUntilDestroyed
Function. Yes, maybe it's still in dev mode
Yeap. It was just an example how to move code out
Pretty cool but I am a big fan of construction injection.
Then you can continue to use them. I hope they won't deprecate them.
you're hidden 💎 🎉
Thank you!
Don't know why Angular is bringing so many things at once..Really hard to get clear idea in Mind What to use and When to use. Confusion hi Confusion hai😅😅
Yeap. Life is pain.
At least almost all of the new things help make it suck less. The main pain point of Angular has always been way too much boilerplate and needless complexity, and I'm happy to see that with every release they are trying really hard to reduce that.
@@cod3r1337 After working in Angular with over a year, I can conclude Angular is the worst framework I have ever used. It's documentation is the worst. Even Angular Material's documentation is worst. They both doesn't mention when to use which things. They just mention definitions with good CSS in their website. All the things needs to be find out by Developer itself. 🤬🤬🤬
can you suggest me road map to learn advanced angular if you can
Just take a real project and do it from start to the end. Like we are doing in this course
ua-cam.com/video/vcfZ0EQpYTA/v-deo.htmlsi=8kMu3zbCa0K_1hxP