Variables become undefined after page reloading
来源:互联网 发布:长沙网络公关 编辑:程序博客网 时间:2024/06/04 18:44
In current angularJS project, I stored some constants in a global array, while that array is set to undefined after I refresh the page.
The explanation I found online:
http://stackoverflow.com/questions/21374643/rootscope-value-used-in-a-controller-is-overridden-when-refreshing-the-page-use
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:
- use a Cookie (in angular you could use the $cookieStore)
- use some of the new HTML5 features like Locale Storage, Web DB or the old DOM Storage (http://en.wikipedia.org/wiki/Web_storage)
- store your data on a server
Then I selected a plugin angular-local-storage as the solution.
https://github.com/grevory/angular-local-storage
0 0
- Variables become undefined after page reloading
- CSS page-break-after 属性
- Idea | Load error: undefined path variables
- web 打印分页page-break-after
- page-break-after设置分页打印
- 控制网页的分页 page-break-after
- crystal report New page after 多一頁空白
- page-break-before和page-break-after 实现分页打印
- hot-reloading
- hot-reloading
- Checking for Undefined, Null, and Empty Variables in JavaScript
- After using jQuery's dialog function, server components in dialog become invalid
- citrix xd 7 After upgrading ,sites and services have become unusable
- What are hogging threads? When do threads become hogged? After what period of time?
- Variables
- Variables
- Variables
- variables
- leetcode single number
- 开发,从需求出发 · 之四 春天在这里
- c#调用Windows API函数的方法
- Sierra: A SIMD Extension for C++
- Consuming RESTful APIs
- Variables become undefined after page reloading
- 从尾到头打印链表
- 【OpenCV入门指南】第十一篇 鼠标绘图
- 2014新生暑假个人排位赛01 A. 学姐的桌面
- Windows系统CPU内存网络性能统计第一篇 内存
- A POJ1611
- 【白话经典算法系列之十三】随机生成和为S的N个正整数——投影法
- 2014新生暑假个人排位赛01 B. 学姐去学车
- HDU 2014 青年歌手大奖赛_评委会打分