0

My task is simple. i have a text field with a button that everytime you press it the local storage will be updated with the text field value.i alredy managed to do that but when i try to get back the value it just shows nothing. if you show me how to do that and how to display only the value(not the id)

<div class="bar bar-header item-input-inset">
  <label class="item-input-wrapper">
    <i class="icon ion-ios7-search placeholder-icon"></i>
    <input ng-model="task" type="search" placeholder="New Task">
  </label>
  <button ng-click="go(task)" class="button button-clear">
    Add 
  </button>
</div>

the controller:

.controller('PlaylistsCtrl', function($scope, $storage , PlaylistService) {
    PlaylistService.get123().then(function (playlists) {  
      $scope.go = function(task) {
        $scope.playlists = playlists;
        var table = $storage('taskData');
        var dataArray= [];

        if (table.getItem("id") === null) {
          table.setItem('id',0);
          table.setItem('value',task);
        }
        else {
            table.setItem('id',table.getItem('id') + 1);
            table.setItem(table.getItem('id') + 1,task);
        }
        for(var i = 1;i<=table.length;i++) {

            //dataArray[i] = dataArray[i] + tasks.getItem(table.getItem('id') + 1);
            //console.log(dataArray);
            console.log(table.getItem(i));
        }
        //console.log(tasks.getItem(table.getItem('id') + 1));
      }
    });
})

the data in the localhost: key ||value taskData {"2":"key value 2","id":1,"value":"key value 1"}

Matan Gubkin
  • 3,019
  • 6
  • 25
  • 44

0 Answers0