清爽与控制器使用的页面时在控制器中使用$ rootscope值被覆盖 [英] $rootscope value used in a controller is overridden when refreshing the page used with that controller
问题描述
在我的angularjs页我使用angularjs的$ rootscope对象传递一个全球性的数据到另一个控制器。在我的控制器我是能够成功地捕捉存储在$ rootscope对象的值和值正确填充,我使用标签控逆变价值。但是,当我刷新页面的价值是越来越消失了。什么是这个问题,以及如何凸轮我克服这种情况。
In my angularjs page I am passing a global data to another controller using the $rootscope object of angularjs. In my controller i am successfully able to catch the value stored in $rootscope object and the value is populating correctly and i am using the value in a label contol. But when I am refreshing the page the value is getting disappeared . What is the problem in this and how cam I overcome this situation.
$ scope.loginname = $ rootScope.curusername;
$scope.loginname = $rootScope.curusername;
感谢和问候
Utpal
Thanks and regards Utpal
推荐答案
如果您重新加载页面,你在JavaScript中变量存储的所有信息丢失。 $ rootScope没有什么更多的则在JavaScript中的变量。如果你想存储的东西,仍然存在重新加载页面至少有以下几种可能:
If you reload your page all information that you store in JavaScript variables are lost. $rootScope is nothing more then a variable in JavaScript. If you want to store something that persists a page reload there are at least the following possibilities:
- 使用一个Cookie(以角度,你可以使用$的CookieStore)
- 使用了一些新的HTML5功能,如区域设置存储,网络DB或旧的DOM存储( HTTP://en.wikipedia。组织/维基/ Web_storage )
- 存储在服务器上的数据
这篇关于清爽与控制器使用的页面时在控制器中使用$ rootscope值被覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!