Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS adding array to cookie store

The snippet is as follows

function CartForm($scope,$cookieStore) {
$scope.invoice = {
    items: [{
        qty: 10,
        description: 'item',
        cost: 9.95}]
};
//want to add the above array to cookie store here 
}

How can i put the above array into cookiestore, and later access it and bind it ?

like image 283
shivram Avatar asked Nov 02 '22 03:11

shivram


1 Answers

The standard way to put and get data in cookies is this:

Put:$cookieStore.put('invoice', $scope.invoice);

Get: return $cookieStore.get('invoice');

This will require a refrence to ngCookies in your app, and also the external angular-cookies script. See this plunk, see the cookie getting logged in the console.

like image 197
Mohammad Sepahvand Avatar answered Nov 11 '22 12:11

Mohammad Sepahvand