繁体   English   中英

什么时候应该使用$ rootScope?

[英]When should I use $rootScope?

我正在阅读有关使用$rootScope在所有应用程序中共享一些数据的讨论。

http://www.linkedin.com/groups/Using-rootScope-store-data-5010991.S.5848794319187644420?view=&srchtype=discussedNews&gid=5010991&item=5848794319187644420&type=member&trk=eml-anet_dig-b_pd-ttl-cn&fromEmail=&ut= 36igDbZcDcIC81

有人说这是一个不好的做法,我们应该使用我们自己的服务来存储这种数据。

尽管我愿意同意,但我有一个问题: $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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM