Angularjs:为什么页面刷新销毁$ rootScope的值? [英] Angularjs: Why page refresh destroy the values of $rootScope?
问题描述
在我的本地路由 http:// localhost:9000 /#/ deviceDetail / 我有一个控制器管理该视图。在进入该视图之前,我将一些变量设置为 $ rootScope
(例如 $ rootScope.dashboards
/ em>)。
In my local route http://localhost:9000/#/deviceDetail/ I have a controller that manage that view. Before going to that view I set some variables to the $rootScope
(for example $rootScope.dashboards
).
在该视图上,我拥有对dashboards属性的访问权,但是当我用 F5
键刷新页面
Once on that view I have acces to dashboards property, but when I refresh the page with F5
key for example the property dashboards is lost.
我试图在localStorage变量中保存 $ rootScope
,但我得到了循环引用 JSON.stringify
方法的问题。
I tried to save the $rootScope
on the localStorage variable but I got circular reference problems with the JSON.stringify
method.
任何提示来管理?
推荐答案
AngularJS是一个JavaScript框架,一切都存储在内存堆中,当你打开一个页面时,堆被启动,在这种情况下,浏览器刷新就像关闭并重新打开页面。
AngularJS is a JavaScript framework, everything is stored in memory heap and the heap is starts when you open a page and it's destroyed after you close it. In this context, browser refresh is like closing and re-opening the page.
要在刷新后保留该值,应将其存储在cookie中,例如 $ cookie
或 sessionStorage / localStorage 。
To keep the value after refresh, you should store it in a cookie, for this you use for example $cookies
or sessionStorage / localStorage as recommended by M K.
这篇关于Angularjs:为什么页面刷新销毁$ rootScope的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!