刷新与该控制器一起使用的页面时,将覆盖控制器中使用的 $rootscope 值 [英] $rootscope value used in a controller is overridden when refreshing the page used with that controller

查看:30
本文介绍了刷新与该控制器一起使用的页面时,将覆盖控制器中使用的 $rootscope 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 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;

感谢和问候乌托尔

推荐答案

如果您重新加载页面,您存储在 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(在 Angular 中,您可以使用 $cookieStore)
  • 使用一些新的 HTML5 功能,例如区域设置存储、Web DB 或旧的 DOM 存储 (http://en.wikipedia.org/wiki/Web_storage)
  • 将您的数据存储在服务器上

这篇关于刷新与该控制器一起使用的页面时,将覆盖控制器中使用的 $rootscope 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆