angularjsangular-local-storageng-storage

I want to add values to local storage on button click using angularjs


I want to add values to local storage on button click using angularjs . I use ngStorage module

Demo for plunker


Solution

  • Firstly, change function cloneItem to accept parameter like

    $scope.cloneItem = function (todo) {
        $scope.$storage.notes.push({
            "age": todo.age, "id":todo.id
        });
    }
    

    Then in your view, pass in the related todo element

    <td><button data-ng-click="cloneItem(todo)">insert id and age to localstorage</button></td>