DEV Community

Cover image for Total Guide To Angular 6+ Dependency Injection — providedIn vs providers:[ ] 💉
Tomas Trajan 🇨🇭 for Angular

Posted on • Updated on • Originally published at Medium

Total Guide To Angular 6+ Dependency Injection — providedIn vs providers:[ ] 💉

I know, I know… Angular 7 is out already but this topic is as relevant as ever! Angular 6 brought us new better providedIn syntax for registration of services into Angular dependency injection mechanism.

As it turned out, this topic can evoke quite emotional responses and there is a lot of confusion across GitHub comments, Slack and Stack Overflow so let’s make this clear once and for all!

📖 What we’re going to learn

  1. Dependency Injection (DI) recapitulation (optional😉)
  2. The Old Way™ of doing DI in Angular  —  providers: []
  3. The New Way™ of doing DI in Angular  —  providedIn: 'root' | SomeModule
  4. Possible scenarios when using providedIn
  5. Recommendation on how to use new syntax in your projects
  6. Summary

Read more...

Top comments (0)