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
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!
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)) }
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.
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
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()?
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
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.
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
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) {}
@@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.
WOW!
great example for inject. first time I subscribe after one video watch
:) That's great! Thanks a lot for the sub and glad you like my content
Good teacher! Easy to understand you deserve more subs!
Thanks for your warm feedback! :)
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
Yeah, the inject() opens so many possibilities.
Ohh, thanks for letting me know about the factory! :)
awesome info
Glad you liked it Paul
Awesome, thank you so much!
You are welcome! :)
awesome explanation! thanks
Thanks for your feedback. Glad you liked it!
that was very powerful, thanks so much
Glad you liked it! :)
This is usefull.
Thank you!
Thanks for your feedback and glad you liked it! :)
Really insightful!
Glad you liked it!
Thanks
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
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!
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))
}
Hello.. thanks for your video...! why i am facing this issue? " NG0203: inject() must be called from an injection context"
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.
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
Yes it's a way to have utility functions, create more abstractions. It offers a great flexibility.
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()?
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
@@CodeShotsWithProfanis Thanks a lot!
Pluck is being deprecated. You should update to use map operator
Ohh yeah, indeed! rxjs.dev/api/index/function/pluck
Thanks for pointing out this
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.
Well, that's a mess. inject() anywhere and everywhere. Peer Reviews, debugging and defect fixing are going to be more fun.
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
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) {}
@@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.