简体   繁体   English

如何刷新本地存储而无需在javaScript或AngularJS中重新加载页面?

[英]How to refresh local Storage without reload the page in javaScript or AngularJS?

How to refresh local Storage without reload the page in javaScript or AngularJS? 如何刷新本地存储而无需在javaScript或AngularJS中重新加载页面? Please show me a demo to resolve this issue. 请给我看一个演示来解决这个问题。

I write a function in a Controller to update a value in localStorage and use this value directly in another Controller but this value wasn't update until i refresh the page. 我在Controller中编写了一个函数来更新localStorage中的值,并在另一个Controller中直接使用此值,但是直到刷新页面后该值才更新。

I just want to know if it's able to refresh (not clear) all value in localStorage after update it without any refreshing action? 我只想知道在更新它之后是否可以刷新(不清除)localStorage中的所有值而无需任何刷新操作?

Here is some demo and example if you have user array then you have to clear user object first after push in userArray as 这是一些演示和示例,如果您有用户数组,则在将userArray推送为时必须首先清除用户对象

$scope. user = {};

Here is the link Jsfiddle demo 这是链接Jsfiddle演示

$scope.addItem = function(user) {
  $scope.userArray.push(user);
  $scope.user = {};
  $localStorage.data = $scope.userArray;
  $scope.userdata = $localStorage.data;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM