Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在努力寻找服务中的哪一个root和platform选项providedIn更好。
root
platform
providedIn
两者都使服务在整个应用程序中可用,后者通过服务,前者通过根注入器。对此有何建议?
root和anyas per官方文档的区别:
any
root:大多数应用程序中的应用程序级注入器。
platform:页面上所有应用程序共享的特殊单例平台注入器。
any: 接收解析的 NgModule 注入器。
更多细节请参考这篇文章。
在我使用的情况下,服务是否被视为单例any?-没有
回到root&之间的原始问题platform,在项目中使用单个应用程序时,它不会改变任何性能方面的东西。