Refreshing an AngularJS and keeping scope variable

2019-04-05 20:44发布

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

Thanks!

2条回答
我想做一个坏孩纸
2楼-- · 2019-04-05 21:00

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.

查看更多
爷、活的狠高调
3楼-- · 2019-04-05 21:11

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.

查看更多
登录 后发表回答