Save a list in local storage

The project I’m working on has 3 pages.
Page 1 - You can set a number (Ex: Numb = 4)
Page 2 - Controller will automatically generates 4 list items with a name.
( 1 - This is list item one
2 - You can change the list item name
3 - This is list item three
4 - These can be edited)
Page 3 - Once you click on a page, you will be redirect to another page which has the full content of the list item

Here’s the problem.
I’m trying to save the list in to local storage. Where I’m having a trouble is, passing multiple objects in to the controller. This is the controller I used for this.

    .controller("SaveController", function($scope){
        $scope.saveData = function(v){
            window.localStorage.setItem("data", v);
        $scope.loadData = function(){


<div ng-controller="SaveController">
    <button class="button" ng-click="saveData(singleVatiable)">Save</button>
    <button class="button" ng-click="loadData()">Load</button>

I want a way to replace ‘singleVariable’ with an array!


You can conver your list to json string and save in in your local storage. then read the string convert it to your object again

JSON.stringify(your list);

JSON.parse(your string);

1 Like