Interacting with Browser Cookies Using the $cookieStore Service

AngularJS provides a couple services for getting and setting cookies: $cookie and $cookieStore. Cookies provide temporary storage in a browser and persist even when the user leaves the webpage or closes the browser.

The $cookie service allows you to get and change string cookie values by using dot notation. For example, the following retrieves the value of a cookie with the name appCookie and then changes it:

var cookie = $cookies.appCookie;$cookies.appCookie = 'New Value';

The $cookieStore service provides get(), put(), and remove() functions to get, set, and remove cookies. A nice feature of the $cookieStore service is that it serializes JavaScript ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.