I am storing two values into an array. They are age and name. How do I use $localStorage to store this array? When I refresh the page, both the array and $localStorage are null.
var app=angular.module("plunker",["ngStorage"]);
app.controller("xCtrl",function($scope,$rootScope,$localStorage){
$scope.list=[]
$scope.x={}
$scope.add=function(x){
$scope.list.push(x);
$localStorage.list= $scope.list;
$scope.$storage= $localStorage.list
$scope.x={}
}
})
This should be your controller code
$scope.list=[]
$scope.x={}
if($localStorage.list){
$scope.$storage=$localStorage.list;
$scope.list=$localStorage.list;
}
$scope.add=function(x){
$scope.list.push(x);
$scope.$storage= $localStorage.list
$scope.x={}
}