#should we use inject vs constructor injection ie: dependency injection? in modern angular?
14 messages · Page 1 of 1 (latest)
https://angular.dev/style-guide#prefer-the-inject-function-over-constructor-parameter-injection Prefer the inject function
thank you ❤️
@shrewd pelican https://youtu.be/CDNyANaVUPs?si=cd3wMU-aLXQlMA8D
Angular DI is getting a new recommendation in the upcoming 2025 style guide: prefer the inject() function over constructor dependency injection. This shift is partly due to how native class fields behave in modern JavaScript. The inject() function also improves code readability and type inference.
Constructor injection is still fully supported...
a bit late but just watched this and it sums it up perfectly with visuals
thank you very very much ❤️
this guy is really good it seems
if it is okay with you may i add you as a friend?
In most cases I would choose inject() over anything else
for me personally i prefer constructor injection.
initialisation of a parameter before the constructor lead to bad design - in every language works that implement OOP.
@dawn grove I thought parameter initialisation is happening at the same time as in constructor kinda?
I'm pretty sure about that, first starting parameters and after that the constructor.
Constructor Timing: The constructor runs after the properties are initialized.
Angular is going towards functional programmimg and not oop so i think i will go with inject it does everything i need (and angular is heading away from oop) react also
a question what is the benefits to not make oop anymore?