angular / code.angularjs.org

code.angularjs.org
151 stars 747 forks source link

Can I save json data in angular(v 1.3.15) cookies and retrieve it #36

Closed rajibbrunel closed 7 years ago

rajibbrunel commented 8 years ago

After calling an api i got following data

$scope.twotap_builtin_cart = { "sites":{ "571fb46730bb1f373d00bdb4":{ "info":{"logo":"https://core.twotap.com/system/sites/logos/571f/b467/30bb/1f37/3d00/bdb4/small/571fb46730bb1f373d00bdb4.png?1468389436927", "name":"Overstock", "url":"overstock.com" },
"currency_format":"$AMOUNT", "coupon_support":false, "gift_card_support":false, "checkout_support":["noauthCheckout"], "shipping_countries_support":["United States of America"], "billing_countries_support":["United States of America"], "shipping_options":{"cheapest":"Default shipping option"}, "returns":"

<span style=\"font-size:16px\">Overstock Return Policy

\r\n\r\n

You can initiate a return for most new and unopened items within 30 days of delivery for a full refund.* You must return items in new or unused condition with all original materials included with the shipment. We must receive your returned items at our processing facility within 45 days of delivery (see Product-Specific Return Policies for exceptions). We inspect all returned items and award a partial refund for opened or used products. If the return is a result of our error or defective product, we will refund the full cost of the merchandise and shipping charges.

\r\n\r\n

If you initiate a return after 30 days, we may issue a partial refund* depending on elapsed time and condition of merchandise.

\r\n\r\n

Defective Product and Returns Due to Our Error

\r\n\r\n

You may return defective items, items damaged at the time of receipt, and incorrect items received without penalty.\ Your return shipping charges will be waived.

\r\n\r\n

When we receive your return, we inspect the item and provide a replacement or issue a refund. If the product is not defective, return shipping fees will apply and/or a partial refund may be issued.

\r\n\r\n

Products Returned After 30 days

\r\n\r\n\r\n\r\n

For more about return policy rules and exceptions you can visit : https://help.overstock.com/app/answers/detail/a_id/1

\r\n", "add_to_cart":{"a6eda98b2e60363a67efb985ef622cea":{"original_url":"http://www.jdoqocy.com/click-3726866-10654383?url=http%3A%2F%2Fwww.overstock.com%2F7281112%2Fproduct.html%3FTRACK%3Daffcjfeed%26CID%3D207442%26fp%3DF","clean_url":"http://www.overstock.com/7281112/product.html?CID=207442", "weight":"1000", "status":"done", "required_fields":{ "quantity":{ "data":[{"input_type":"text","input_name":"INPUT"}]}}, "discounted_price":null, "original_price":null, "pickup_support":false, "url":"http://www.overstock.com/7281112/product.html?TRACK=affcjfeed&CID=207442&fp=F","required_field_values":{},"required_field_names":["quantity"],"categories":["Sports & Toys","Toys & Hobbies","Games & Puzzles","Board Games"],"description":"

ITEM#: 14756475

From a different age when people had time to sit and play games together, the Britannia Games Compendium is packed full of fun. Based on a product from the 1940s the Britannia Games Compendium has something for all ages.\n

\n","alt_images":["http://ak1.ostkcdn.com/images/products/7281112/Perisphere-and-Trylon-The-Britannia-Compendium-of-Games-f17b48f6-8c81-4a0e-af12-fa2e3d97ac25_320.jpg"],"image":"http://ak1.ostkcdn.com/images/products/7281112/Perisphere-and-Trylon-The-Britannia-Compendium-of-Games-f17b48f6-8c81-4a0e-af12-fa2e3d97ac25_600.jpg","price":"$37.49","title":"Perisphere and Trylon The Britannia Compendium of Games"}}}},"user_id":null,"unknown_urls":[],"cart_id":"5785d83c493bfb7f2a352cde","notes":null,"country":"us","stored_field_values":{},"message":"done","description":"AddToCart has been completed.","product_urls":[]}

Then I saved this data inside cookies. $cookies['xxx'] = $scope.twotap_builtin_cart;

Now, when i tried to retrieve this data from cookies it showed me as Object. I tried to print it inside console it showed object Object

var t = $cookies['xxx']; console.log(t); $scope.recentItemsx = angular.toJson(t); console.log($scope.recentItemsx); console.log(JSON.parse($cookies['xxx'])); I tried JSON.parse , anglar.toJson and jsonstringify. Nothing can solve this

I tried with cookie store

$cookieStore.put('recentx',$scope.twotap_builtin_cart); I also got following warning Cookie in console

'recentx' possibly not set or overflowed because it was too large (6675 > 4096 bytes)! in another controller i printed console.log($cookieStore.get('recentx')); It give me output [object Object]. I can not work with this. I need json data for ng-repeat purpose I can not putObject or Get Object because those are for angular version greater than 1.4

Narretz commented 7 years ago

Bugs / Feature Requests must be reported at: https://github.com/angular/angular.js/issues