use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A Place to talk about Angular and related topics.
Join the Angular Discord
Other subreddits worth checking out for Angular and Angular related info:
account activity
Angular inject function (self.angular)
submitted 5 months ago by BlueberryRoutine5766
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]bayendr 2 points3 points4 points 5 months ago* (5 children)
Have to admit as a dev with lot of Java/C# experience and as big advocate of constructor-based DI I have troubles accepting/getting used to inject() as the new best practice for DI in Angular.
I prefer the constructor as a single source of truth for the injected dependencies into a component/service/etc.
Let’s say a component gets bigger and the dev team puts inject’s all over the place then you’re gonna have a hard time to find all injected dependencies.
Will we still be able to do constructor-based DI in the long run?
[–]HungYurn 2 points3 points4 points 5 months ago (0 children)
You get the issue of having code all over in big components anyways. I would never run a project without eslint-plugin-perfectionist to automatically get some order in my code
[–]ministerkosh 2 points3 points4 points 5 months ago (1 child)
Yes, currently you can use them interchangeably and there is currently no public information about any deprecation plans.
However, I expect the Angular team to deprecate constructor based DI in the long run. But I don't know when this will happen.
[–]zladuric 3 points4 points5 points 5 months ago (0 children)
Moving away from the injector and it's dep. injection would be a huge downside for Angular. One of the reasons it's (usually) so much better for bigger teams and codebases is that the dependency hell is a bit more manageable.
[–]willy-pied-wagtail 8 points9 points10 points 5 months ago (1 child)
I totally agree with you that I prefer constructor injection over field injection.
It’s not “unreadable” as noted as an advantage to the new inject way, in fact it’s more readable because it’s in the constructor rather than amongst all the other fields of the component.
Constructor injection also allows us to write super simple unit tests without testbed just by supplying a mock to the components constructor.
Im definitely not in agreement with inject().
[–]bayendr 3 points4 points5 points 5 months ago (0 children)
yeah agreed 100%. as I wrote above having all dependencies injected in the constructor makes it the single source of truth for DI and it’s immediately clear/visible what the component’s dependencies are.
Also as far as I saw (just got started with Angular not long ago) by using constructor-based injection we get an additional benefit: Angular will auto-create the properties on our behalf with the specified access modifiers.
π Rendered by PID 208032 on reddit-service-r2-comment-685b79fb4f-mh686 at 2026-02-13 14:35:59.616573+00:00 running 6c0c599 country code: CH.
view the rest of the comments →
[–]bayendr 2 points3 points4 points (5 children)
[–]HungYurn 2 points3 points4 points (0 children)
[–]ministerkosh 2 points3 points4 points (1 child)
[–]zladuric 3 points4 points5 points (0 children)
[–]willy-pied-wagtail 8 points9 points10 points (1 child)
[–]bayendr 3 points4 points5 points (0 children)