Angular's `inject` function, introduced in Angular 14, offers an alternative to constructors for injecting dependencies. It simplifies inheritance, reduces boilerplate code, eliminates the need for parameter decorators, and provides more concise and type-safe code. However, it can lead to scattered and hidden dependencies, making testing and code comprehension more challenging. Understanding the Injection Context is crucial for using `inject` effectively. Despite some concerns, `inject` has proven useful and is recommended over constructor parameters for consistent coding practices.

8m read timeFrom dev.to
Post cover image
Table of contents
Classes lose their "purity"Scattered dependenciesHidden dependenciesWhat is an Injection Context?Minor causes of frustration I've seen on the webTakeaways

Sort: