Get Specific Data From ngStorage

130 Views Asked by At

I have a bunch of data on JSON using LocalStorage from ng-storage like this,

[Object { judul="Just",  isi="Testing"}, Object { judul="To",  isi="Get"}, Object { judul="Specific",  isi="Data"}]

but I want to get one specific data to get the "isi" value, how to do that ?

1

There are 1 best solutions below

0
On

You can do this by adding a get function to your factory

for example :

.factory ('StorageService', function ($localStorage) {

    $localStorage = $localStorage.$default({
    things: []
   });

  var _getAll = function () {

    return $localStorage.things;
  };


      //-----


      var _get = function (isi) {
        for( var i = 0; i < $localStorage.things.length ; i++ ){

            if( $localStorage.things[i].isi === isi  ){

            return $localStorage.things[i]; 
            }

        }
      }


      return {
        getAll: _getAll,
        get : _get
      };
    })

and in your controller you can get the specific data by passing the id of your object

var objectInlocal = StorageService.get(Thing.isi);