1

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

Demo for plunker

2 Answers 2

4

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>
Sign up to request clarification or add additional context in comments.

Comments

0

To skip duplicates a small check is needed

$scope.cloneItem = function (todo) {
for (var i = 0; i < $scope.$storage.notes.length - 1; i++) {
    if ($scope.$storage.notes[i].age !=todo.age && $scope.$storage.notes[i].id!=todo.id ) {
    $scope.$storage.notes.push({
        "age": todo.age, "id":todo.id
    });
   }
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.