Angular Inject Function - Better Than Constructor

  Рет қаралды 12,986

Monsterlessons Academy

Monsterlessons Academy

Күн бұрын

Пікірлер: 58
@MonsterlessonsAcademy
@MonsterlessonsAcademy 3 ай бұрын
WATCH NEXT: Angular Interview Questions and Answers - Dominate Your Next Interview - kzbin.info/www/bejne/a3LCin6ii7yAhtEsi=2DCn7yspEAAJ2H6l
@hamza201183
@hamza201183 Жыл бұрын
Wow there are so many things to learn in Angular...
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Yeap. Unfortunately they don't want to stop.
@prasoon2510
@prasoon2510 4 ай бұрын
You are awesome.. you explain in very easy and practical manner. Thank you
@MonsterlessonsAcademy
@MonsterlessonsAcademy 4 ай бұрын
You are welcome!
@tomozi1
@tomozi1 Жыл бұрын
Отличная подача! Как всегда материал на высоте
@stratfanstl
@stratfanstl 7 күн бұрын
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.
@MonsterlessonsAcademy
@MonsterlessonsAcademy 7 күн бұрын
Yeap
@e-jarod4110
@e-jarod4110 Жыл бұрын
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
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Yeap!
@ythalorossy
@ythalorossy 7 ай бұрын
Amazing explanation.
@MonsterlessonsAcademy
@MonsterlessonsAcademy 7 ай бұрын
Glad you think so!
@fadil2671
@fadil2671 Жыл бұрын
nice video, now i need to refactor all my codes 😁😁
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Go for it!
@hamza201183
@hamza201183 Жыл бұрын
Many thanks, great video as always.
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Glad you enjoyed it
@advance5189
@advance5189 6 ай бұрын
Awesome explanation and moreover, your English is so clear that I wanna listen to you and listen.. Keep going!
@MonsterlessonsAcademy
@MonsterlessonsAcademy 6 ай бұрын
Thank you! 😃
@ytamb01
@ytamb01 Жыл бұрын
That was really good - both creating re-usable code outside your component and a much cleaner way of extending components. Thanks very much.
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
You're welcome!
@Brendan2Alexander
@Brendan2Alexander Жыл бұрын
Awesomely helpful! Thank u
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
You're welcome!
@MrGCastilhos
@MrGCastilhos Жыл бұрын
Amazing content, thanks a lot
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
My pleasure!
@banafish
@banafish Жыл бұрын
Great Video! What font and theme are you using here? Very readable
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
It's gruvbox and monaco font.
@visufactmanufacturing7712
@visufactmanufacturing7712 Жыл бұрын
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()".
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
There are no guidelines. Maybe we get eslint rules at some point.
@mohammedsalah932
@mohammedsalah932 Жыл бұрын
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 ?
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
I don't have a specific video about OnChange
@FarazKhan-fn9gs
@FarazKhan-fn9gs 7 ай бұрын
Please make it one​@@MonsterlessonsAcademy
@cod3r1337
@cod3r1337 Ай бұрын
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
@MonsterlessonsAcademy
@MonsterlessonsAcademy Ай бұрын
It's not my idea. I also stole it :D
@theWorldOfIss
@theWorldOfIss 2 ай бұрын
After 1 year I am knowing it😅
@MonsterlessonsAcademy
@MonsterlessonsAcademy 2 ай бұрын
Awesome!
@thirukumaran6034
@thirukumaran6034 Жыл бұрын
Your courses are short and sweet ❤. Can you please create a new session for unit testing inject() function
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
I added it to the list of future videos. Thank you for the idea!
@JonatanPetersson
@JonatanPetersson Жыл бұрын
@@MonsterlessonsAcademy Would really like this too. Especially where you've extracted them into functions
@DavidKooffreh
@DavidKooffreh 5 ай бұрын
For the final part what is the advantage of using that over ngOndestroy
@MonsterlessonsAcademy
@MonsterlessonsAcademy 5 ай бұрын
You make a reusable function which should not be duplicated in every single component with ngOnDestroy
@DavidKooffreh
@DavidKooffreh 5 ай бұрын
@MonsterlessonsAcademy Thanks that was very useful information
@cod3r1337
@cod3r1337 Ай бұрын
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
@mjpanebianco8162
@mjpanebianco8162 Жыл бұрын
Does this method of injection protect against creating multiple instances of a service you intend to be a singleton?
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
It doesn't protect against anything. It is just the same like defining it in the constructor
@wiliam334
@wiliam334 Жыл бұрын
How do we mock them in the tests now? Ta
@cod3r1337
@cod3r1337 Ай бұрын
The same way we have always done since Angular 2: Using TestBed.
@alexmatveev7730
@alexmatveev7730 Жыл бұрын
For destroy/unsubscribe we can use takeUntilDestroyed Function. Yes, maybe it's still in dev mode
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Yeap. It was just an example how to move code out
@val-do
@val-do Жыл бұрын
you're hidden 💎 🎉
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Thank you!
@emmanuelU17
@emmanuelU17 Жыл бұрын
Pretty cool but I am a big fan of construction injection.
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Then you can continue to use them. I hope they won't deprecate them.
@4444-c4s
@4444-c4s Жыл бұрын
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😅😅
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Yeap. Life is pain.
@cod3r1337
@cod3r1337 Ай бұрын
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.
@4444-c4s
@4444-c4s Ай бұрын
@@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. 🤬🤬🤬
@MuhamedHassan-ry5fs
@MuhamedHassan-ry5fs 8 ай бұрын
can you suggest me road map to learn advanced angular if you can
@MonsterlessonsAcademy
@MonsterlessonsAcademy 8 ай бұрын
Just take a real project and do it from start to the end. Like we are doing in this course kzbin.info/www/bejne/rJTJi2N7htWMiqMsi=8kMu3zbCa0K_1hxP
Advent of Code 2024 in BQN Day 3!
10:14
code_report
Рет қаралды 1 М.
How to Fight a Gross Man 😡
00:19
Alan Chikin Chow
Рет қаралды 21 МЛН
Angular 17 Defer - Improve Performance in Your Application
11:27
Monsterlessons Academy
Рет қаралды 9 М.
Why I decided to switch to the inject() function in Angular
6:10
Joshua Morony
Рет қаралды 61 М.
Top 5 Angular Mistakes - You Must Know Them
10:32
Monsterlessons Academy
Рет қаралды 60 М.
Angular Unit Testing Crash Course - Make Your Project Bullet Proof
19:48
Monsterlessons Academy
Рет қаралды 16 М.
Change Detection in Angular - You Project Is 20x Slower!
15:16
Monsterlessons Academy
Рет қаралды 73 М.
Angular Authentication and Authorization - The Correct Way
23:30
Monsterlessons Academy
Рет қаралды 36 М.
How to Fight a Gross Man 😡
00:19
Alan Chikin Chow
Рет қаралды 21 МЛН