This is a weekly posting, covering the latest updates from the Angular community.
inject
function in Angular 14
For more than half a year, we have been waiting for Standalone Components and typed forms. Now, as it is just a matter of a few weeks, we suddenly get a third feature with the potential for significant changes.
Younes Jaaidi published an article about an inject function which was added in the rc-1 for Angular 14. With that function, you can synchronously request elements from the dependency injection. Use cases are that you can use it instead of the @Inject decorator to gain more type safety or use it instead of the constructor. That could reduce the boilerplate code.
🎉 Here it is! A blog post covering the latest, tiniest & cutest #Angular 14 feature that enables:
✨ Tree-Shakable State Management
✨ InjectionToken Type Inference
✨ Simplified Abstract Base Class
✨ Boilerplate Reduction
🎁 Patterns & Anti-Patterns
marmicode.io/blog/angular-i…17:59 PM - 20 May 2022
There are some constraints as well. For example, it can only be used in the construction context, including the constructor itself and field and function declarations. And it is only available inside Components, Services, Pipes, and Directives. So Angular will not abandon classes and use functions.
Younes summarized potential use cases along anti-patterns in his article. But, as always, when something new arrives, it is a bitlittle unclear if and how it will affect the way we will write Angular applications in the future.
Article series Angular 14 - Netanel Basal
Netanel Basal also wrote an article about the inject function. Actually, he wrote a complete series of all upcoming features in Angular 14. So definitely, worth reading it.
@angular v14 will be released soon, and I can't wait.
🔥🚀This version is awesome! Here are the main features you need to know:09:19 AM - 19 May 2022
Top comments (0)