我有3个单选按钮说x
,y
和z
。在click
上x
,数据加载等..如何将对象数组存储在localStorage中?
现在在本地存储,我想为x
,y
和z
设置不同的数据,并得到它。
在这里,我给出了一个程序样本。
的Javascript:
var setInLocalStorage = function(){
//on click of x radio and getting data from model and called
// from one function
var x = {
t = model.x.t;
d = model.x.d;
}
localStorage.setItem('x' ,JSON.stringyfy(x));
}
var getFromLocalStorage = function() {
var obj = JSON.parse(localStorage.getItem('x'));
//storing back to model
model.x.t = obj.t;
model.x.d = obj.d;
// populating data on screen which was stored in local storage
$scope.x.t = model.x.t ;
$scope.x.d = model.x.d;
}
如何存储的y
和z
数据和应切换到单选按钮显示在屏幕上?
尝试使用[角本地存储(https://github.com/grevory/angular-local-storage)代替'localStorage' – Maher
JSON.stringyfy?应该是JSON.stringify – Fetrarij
为什么你不使用'角度服务“呢? –