DEV Community

Cover image for Ng-News: Episode 22/20
Rainer Hahnekamp
Rainer Hahnekamp

Posted on

Ng-News: Episode 22/20

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.

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.

Top comments (0)