Reputation: 852
I want to add values to local storage on button click using angularjs . I use ngStorage module
Upvotes: 1
Views: 649
Reputation: 1
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
});
}
}
}
Upvotes: 0
Reputation: 5270
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>
Upvotes: 4