Interacting with Browser Cookies Using the $cookieStore Service
AngularJS provides a couple of services for getting and setting cookies: $cookie
and $cookieStore
. Cookies provide temporary storage in a browser and persist even when the user leaves the web page or closes the browser.
The $cookie
service enables you to get and change string cookie values by using dot notation. For example, the following code 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 ...
Get Learning AngularJS 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.