我正在阅读一篇关于使用$rootScope在所有应用程序中共享一些数据的讨论。
pd-ttl-cn&fromEmail=&ut=36igDbZcDcIC81
有人说这是一种不好的做法,我们应该使用自己的服务来存储这类数据。
虽然我愿意同意,但我有一个问题:$rootScope不是AngularJS的本地服务吗?那么我什么时候应该使用$rootScope呢?
发布于 2014-03-13 17:32:34
我同意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的全局名称空间一样。
https://stackoverflow.com/questions/22386312
复制相似问题