[英]providedIn platform vs root
I am struggling to see which one of the root
and the platform
options for providedIn
in a service is better.我很努力,看看哪个的一个
root
和platform
的选择providedIn
的服务比较好。
Both make a service available in the whole application, the latter through a service and the former through the root injector.两者都在整个应用程序中提供服务,后者通过服务,前者通过根注入器。 Any advice on this?
对此有何建议?
The difference between the root
and any
as per offical documentation : root
和any
根据官方文档的区别:
root
: The application-level injector in most apps. root
:大多数应用程序中的应用程序级注入器。
platform
: A special singleton platform injector shared by all applications on the page. platform
:页面上所有应用程序共享的特殊单例平台注入器。
any
: The NgModule injector that receives the resolution. any
:接收解析的 NgModule 注入器。
For more details please refer this article .有关更多详细信息,请参阅这篇文章。
Is a service considered a singleton in the case that I use any
?在我使用
any
的情况下,服务是否被视为单例? - No -没有
To go back to the original question between root
& platform
, when using a single application in your project, it doesn't change anything performance wise.回到
root
和platform
之间的原始问题,在您的项目中使用单个应用程序时,它不会改变任何性能明智的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.