Angular's dependency injection (DI) differs from .NET and Java because TypeScript interfaces are erased at compile time and don't exist in the resulting JavaScript. This means Angular uses classes as DI tokens instead of interfaces. Despite injecting a class directly, Angular still provides true DI — you can swap implementations without changing consumer code by using the `provide`/`useClass` pattern in the module providers array. Extending the original service class and registering the new one as a replacement allows partial method overrides while inheriting the rest.

6m read timeFrom playfulprogramming.com
Post cover image
Table of contents
Introduction Copy link Link copied!Why we cannot use Interface Copy link Link copied!How it is Dependency Injection if We are dependent on Class Instance Copy link Link copied!Conclusion Copy link Link copied!

Sort: