2014-03-13 196 views
1

我在阅读有关使用$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

回答

2

我同意Kibsaim在说线程的注释:在$rootScope

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. 

把对象是坏在那个污染JavaScript的全局命名空间是坏的相同方式从长远来看。

相关问题