0

I'm learning my Angular and attempting to develop a simple shopping cart.

I'd like to add NgCookies into my application to store the item in a cart.

Can someone advise how I add a object to a cookie?

I have the following function on my controller ...

 this.addItemToBasket = function(item) {

        //that.basket.push(item);

        $cookies.put("shopping-cart", item,
        {
        });

        alert($cookies.get("shopping-cart"));
    },

If you need more information or code, please comment.

1 Answer 1

2

In Angular 1.4 you can do this below.

  var obj = {};
  $cookies.putObject('name', obj);

If you are in versions below, you could use JSON.Stringify(obj);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.