Learn How to Use the Inject Method in Angular 14

  Рет қаралды 8,401

Code Shots With Profanis

Code Shots With Profanis

Күн бұрын

Пікірлер: 37
@ronavraham-r3h
@ronavraham-r3h Жыл бұрын
WOW! great example for inject. first time I subscribe after one video watch
@CodeShotsWithProfanis
@CodeShotsWithProfanis Жыл бұрын
:) That's great! Thanks a lot for the sub and glad you like my content
@owenjaspervargas1408
@owenjaspervargas1408 Жыл бұрын
Good teacher! Easy to understand you deserve more subs!
@CodeShotsWithProfanis
@CodeShotsWithProfanis Жыл бұрын
Thanks for your warm feedback! :)
@arthurfedotiew3609
@arthurfedotiew3609 2 жыл бұрын
Thank you master Profanis!) The most valuable one thing to learn from this is that inheritance begins to seem a little more useful now) Btw, inject() in a context of factory provider could be used for a pretty long time, I think when ivy got into a play or so
@CodeShotsWithProfanis
@CodeShotsWithProfanis 2 жыл бұрын
Yeah, the inject() opens so many possibilities. Ohh, thanks for letting me know about the factory! :)
@nfallycoly6362
@nfallycoly6362 Жыл бұрын
Awesome, thank you so much!
@CodeShotsWithProfanis
@CodeShotsWithProfanis Жыл бұрын
You are welcome! :)
@rafaelpanayiotou1833
@rafaelpanayiotou1833 2 жыл бұрын
Hello.. thanks for your video...! why i am facing this issue? " NG0203: inject() must be called from an injection context"
@CodeShotsWithProfanis
@CodeShotsWithProfanis 2 жыл бұрын
The inject() method works only during the class construction. Having said that, it's OK to use the inject in the constructor, but it's too late if you try to use this in the ngOnInit hook. The inject requires the initialization context, which is available only during the class construction.
@antt0023
@antt0023 2 жыл бұрын
How did you make the param name to show on vscode? Like in the logger token, it shows _desc as param name. Really helpful video. Thanks man
@CodeShotsWithProfanis
@CodeShotsWithProfanis 2 жыл бұрын
I really like the feature with the argument names :) Add this in your settings.json: "typescript.inlayHints.parameterNames.enabled": "all" Glad you liked the video!
@fahadgaliwango4502
@fahadgaliwango4502 2 жыл бұрын
Thak you profanis . Have understood it as way to reduce dependecies in the constructor , so they can be declared as global functions or variables, is that a correct take home
@CodeShotsWithProfanis
@CodeShotsWithProfanis 2 жыл бұрын
Yes it's a way to have utility functions, create more abstractions. It offers a great flexibility.
@harunmn
@harunmn 2 жыл бұрын
awesome explanation! thanks
@CodeShotsWithProfanis
@CodeShotsWithProfanis 2 жыл бұрын
Thanks for your feedback. Glad you liked it!
@ThodorisHadoulis
@ThodorisHadoulis 2 жыл бұрын
Really insightful!
@CodeShotsWithProfanis
@CodeShotsWithProfanis 2 жыл бұрын
Glad you liked it!
@hadirahmani7943
@hadirahmani7943 2 жыл бұрын
that was very powerful, thanks so much
@CodeShotsWithProfanis
@CodeShotsWithProfanis 2 жыл бұрын
Glad you liked it! :)
@paulh6933
@paulh6933 2 жыл бұрын
awesome info
@CodeShotsWithProfanis
@CodeShotsWithProfanis 2 жыл бұрын
Glad you liked it Paul
@orshalmayev7077
@orshalmayev7077 2 жыл бұрын
This is usefull. Thank you!
@CodeShotsWithProfanis
@CodeShotsWithProfanis 2 жыл бұрын
Thanks for your feedback and glad you liked it! :)
@OlehBiblyi
@OlehBiblyi 2 жыл бұрын
Thank you, very interesting, I think I need to repeat a lot of stuff about Class, to properly understand what is going on here ). Also what is a difference between take(1) and first()?
@CodeShotsWithProfanis
@CodeShotsWithProfanis 2 жыл бұрын
The difference between take(1) and first() operators is in the emitted value. If you use the first() operator and the stream completes without any emitted value, then an error is thrown. However, the take(1) will complete the stream without error. I hope this helps
@OlehBiblyi
@OlehBiblyi 2 жыл бұрын
@@CodeShotsWithProfanis Thanks a lot!
@seanpheneger6632
@seanpheneger6632 2 жыл бұрын
Pluck is being deprecated. You should update to use map operator
@CodeShotsWithProfanis
@CodeShotsWithProfanis 2 жыл бұрын
Ohh yeah, indeed! rxjs.dev/api/index/function/pluck Thanks for pointing out this
@seanpheneger6632
@seanpheneger6632 2 жыл бұрын
Yeah, sure thing. I used it a lot in a few of my older projects but have been updating any new files to use map now so it'll be less painful of a migration when it is fully removed. Thanks for the video. It was insightful.
@diyvideos9737
@diyvideos9737 2 жыл бұрын
Thanks
@XHANITRUNGUMANOS
@XHANITRUNGUMANOS 2 жыл бұрын
Hello . I would like to add that we can use the Inject method in any other hook or lifecycle , except from constructor utilizing the power of closures, as we are able to store the injected token inside the closure scope and still use values in the returned function. 😁😁😁| exort const dispatchSearch = (): ((search: string) => void) => { const store = inject(Store); return (search) => store.dispatch(new SetSearch(search)) }
@zshn
@zshn 2 жыл бұрын
Well, that's a mess. inject() anywhere and everywhere. Peer Reviews, debugging and defect fixing are going to be more fun.
@jonasjanaitis436
@jonasjanaitis436 2 жыл бұрын
I spen half a day figuring out what a hell is going on. In one code I found this implementation: constructor(@Inject(HttpClient) private http: HttpClient). But this constructor for me always returned undefined...I think it worked in older versions of Angular. At least now I can go to sleep in relief, thank you
@CodeShotsWithProfanis
@CodeShotsWithProfanis 2 жыл бұрын
Both inject and @Inject are valid per case. In case you want to use the HttpClient in your constructor, you can even do constructor(private http: HttpClient) {}
@jonasjanaitis436
@jonasjanaitis436 2 жыл бұрын
@@CodeShotsWithProfanis I have Rest class that is not marked as @Injectable but it is like an abstract class. Then I have two services that extend that Rest class and is marked as @Injectable and these services are in provider[]. Rest class has HttpClient, but as I said before it always returns undefined when I do constructor(@Inject(HttpClient) private http: HttpClient) in Rest class. But http:HttpClient = inject(HttpClient) works fine.
APP_INITIALIZER Token in Angular (Advanced, 2022)
23:56
Decoded Frontend
Рет қаралды 23 М.
Why I decided to switch to the inject() function in Angular
6:10
Joshua Morony
Рет қаралды 63 М.
Andro, ELMAN, TONI, MONA - Зари (Official Music Video)
2:50
RAAVA MUSIC
Рет қаралды 2 МЛН
Every team from the Bracket Buster! Who ya got? 😏
0:53
FailArmy Shorts
Рет қаралды 13 МЛН
Learn How to Use Angular's 17 Defer Block
23:50
Code Shots With Profanis
Рет қаралды 4,2 М.
The inject function in Angular is not just a toy
3:55
Joshua Morony
Рет қаралды 17 М.
How Dependency Injection In #Angular Works
23:02
Code Shots With Profanis
Рет қаралды 1,8 М.
Angular Inject Function - Better Than Constructor
8:10
Monsterlessons Academy
Рет қаралды 13 М.
Component-Less and Empty-Path Routes in Angular (2023)
14:07
Decoded Frontend
Рет қаралды 14 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 915 М.
Angular Injection Token - When to Use It?
6:19
Monsterlessons Academy
Рет қаралды 14 М.
ngTemplateOutlet is WAY more useful than I realised
16:36
Joshua Morony
Рет қаралды 78 М.
Get to Know How The Angular RedirectTo Function Works
10:06
Code Shots With Profanis
Рет қаралды 786
три кошака и ростелеком
0:26
Мистер Денала
Рет қаралды 2,4 МЛН
ТЕЛЕФОН МЕНЯЕТ ЦВЕТ😅 #upx
0:34
RanF
Рет қаралды 639 М.