👨🏫 Co-Founder of This is Learning, Organizer of AarhusJS
✍️ Writer, Speaker, FOSS Maintainer 📗 Author
🏆 Microsoft MVP 🌟 GitHub Star
🌊 Nx Champion 🦸 Angular Hero of Education
We can also reference set Angular module as the provider scope, using providedIn: MyModule.
Using strings and other primitive values as dependency injecton tokens has been deprecated since version 4.0.0 and should not be encouraged because of this.
👨🏫 Co-Founder of This is Learning, Organizer of AarhusJS
✍️ Writer, Speaker, FOSS Maintainer 📗 Author
🏆 Microsoft MVP 🌟 GitHub Star
🌊 Nx Champion 🦸 Angular Hero of Education
I have an example of what to use a module scope for in my article "Tree-shakable dependencies in Angular projects". Of course, the providedIn: MyModule syntax is just the tree-shakable way of expressing the module provider scope that's been around since v2.0.0 (the providers metadata for Angular modules).
I would say remove it. It's been deprecated for almost 3 years (since v4.0.0). Some projects use it for dynamic injection tokens, but that's an edge case and should be implemented using a Map of InjectionTokens or something like that instead.
Thank you for creating this 👏
A few comments:
providedIn: MyModule
.Thank you Lars. Very good input.
I'll add providedIn: MyModule. Also thinking about examples when to use what. Especially now with Ivy and the "any" provider 🤔
Good point. What would you say, would you completely remove the example or rather mark it as deprecated?
Thank you for your feedback 💪
I have an example of what to use a module scope for in my article "Tree-shakable dependencies in Angular projects". Of course, the
providedIn: MyModule
syntax is just the tree-shakable way of expressing the module provider scope that's been around since v2.0.0 (theproviders
metadata for Angular modules).I would say remove it. It's been deprecated for almost 3 years (since v4.0.0). Some projects use it for dynamic injection tokens, but that's an edge case and should be implemented using a
Map
ofInjectionToken
s or something like that instead.Thank you. Great article.