Refreshing an AngularJS and keeping scope variables

廉价感情. 提交于 2019-12-05 19:57:03

问题


Is it possible to keep variables on scope after refreshing my AngularJS page? How do I get this configured?

Thanks!


回答1:


There are several options to do this,

  1. For smaller data you could use the $cookieStore, for data that is under 4k
  2. Another option, especially with large data sets, would be to use Local Storage and then retrieve the data on page load/reload.
  3. if it is only a very small amount of data, or data that is used through out multiple page you could use $rootscope, but this is not the best option as it just like polluting the global name space.
  4. The last option, depending on how the data is retrieved, a service could be implemented, that is basiclly a singlton that can be passed to various angular scope.

All of this is dependent on the data in which you want to store. If you provide more info on what you are trying to achieve then the options could be narrowed.




回答2:


I realize this is an old Question / Answer but after running into page refresh $scope and a multi-step form issues, I wanted to post what I found to assist. @Jared Reeves is correct above, but I think gsklee ngStroage is a fantastic tool for the question's requirements.



来源:https://stackoverflow.com/questions/24789252/refreshing-an-angularjs-and-keeping-scope-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!