Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Is there a method to save, read and modify an array of objects in the cookieStore with angularJs?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

No there is not. You have to do the array modifications by yourself and store the array back to the cookieStore:

$cookieStore.put('key', []);
var array = $cookieStore.get('key');
array.push('value');
$cookieStore.put('key', array);
share|improve this answer
    
Thanks a lot....I will try it!!! –  user880386 Jan 7 '14 at 20:19
    
to get this array in other page how I can it? –  user880386 Jan 7 '14 at 21:03
    
what did you mean with "page". the cookieStore is bound to your origin - so your full SPA have access to this information –  michael Jan 7 '14 at 21:13
    
I would be interested if anyone has developed an angularjs/cookiestore module that would automatically reload (or create) a property on a scope and save it whenever the model changes. –  C Fairweather Jan 7 '14 at 21:46

I would advise you check out this module that allows you to easily use local storage or cookie storage and bind it to your scope:

http://ngmodules.org/modules/angularLocalStorage

Example: http://plnkr.co/edit/Y1mrNVRkInCItqvZXtto?p=preview

var eS = angular.module('exampleStore', ['localStorage']);

  eS.controller('MainCtrl',['$scope','$store',function($scope, $store) {
      $store.bind($scope, 'test', 'Some Default Text');

      $scope.clearTest = function(){ 
          $store.remove('test'); 
      };
  }]);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.