Angular Js: Cookies

$cookies is the angular service responsible for dealing with cookies.

In order to work with cookies using angular, we need to download the file angular-cookies.js (or min.js) that can be found here. In addition, we need to include the module ngCookies in the array of dependencies of our angular app.

There are two types of cookies that Angular supports:

Value cookie: This type of cookie can store simple data.

Object cookie: This type of cookie can store an object.

In our example we will demonstrate the methods that can be used in both types.

The methods are: put, get and delete (add the suffix Object to deal with object cookies).

You can use the the console and application tab of dev tools of the browser to track the changes made by our code.