[英]When should I use $rootScope?
我正在阅读有关使用$rootScope
在所有应用程序中共享一些数据的讨论。
有人说这是一个不好的做法,我们应该使用我们自己的服务来存储这种数据。
尽管我愿意同意,但我有一个问题: $rootScope
是否不是AngularJS的本地服务 ? 那我什么时候应该使用$rootScope
?
我同意Kibsaim在上述主题中的评论:
Hello Carla,
I will recommend not overloading rootScope, although what you comment can be done, I will
recommend you using a service with state, and inject it over controllers to share the
information.
That should be cleaner on the long run.
从长远来看,将对象放在$rootScope
是有害的,就像污染Javascript的全局名称空间是有害的一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.