6ffeog
Last Updated: February 25, 2016
·
24.57K
· bleakgadfly
45c307fd94671e91c9ebebf29a636214

Using ngCookies in AngularJS

The documentation on ngCookies in Angular is pretty vague so here is a little write-up how to get started with ngCookies.

For some reason, Angular 1.0.4 does not seem to include the ngCookies module so I had to download the cookies module manually and include it in my project. Note that if you just include the URL for the raw data on Github it won't work on IE because of a MIME mismatch.

In your App Module statement, add 'ngCookies' as a dependency:

var App = angular.module('myModuleName', ['ngCookies']);

Add the $cookies service as a parameter to the controller you want it in and access the cookie properties as a regular object

function SomeFunc($scope, $cookies) {
        $cookies.NameOfMyCookie = "Setting a value";
        alert($cookies.NameOfMyCookie);
}

Gist

Say Thanks
Respond

2 Responses
Add your response

8192
0 cdhk 3yk5rekeetrzarc  wffzxxhitrzwpr  7s4pw7c7nkui4eyirnd408w28p9aosjxjbrgze

This is secure to use in productions app?

over 1 year ago ·
8407
45c307fd94671e91c9ebebf29a636214

Depends on your use, I guess.

over 1 year ago ·