Menu

Angular injection context lint rules: say goodbye to NG0203 error

DEV Community: angular·Cyrille Tuzi·6 months ago
#WoZJz9Eg
#dev#class#code#inject#injection
Reading 0:00
15s threshold

Angular is changing a lot these days. One of the major changes that most developers are already aware of is how to inject dependencies.

// Before @ Component () export class ProductPage { constructor ( private readonly productsApi : ProductsApi ) {} }

// Now @ Component () export class ProductPage { private readonly productsApi = inject ( ProductsApi ); }

From compilation to runtime error

The constructor-based injection was more limited, but it was safe on the compilation level.

On the other hand, inject() and similar functions must be called from an injection context .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.