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);
}
Written by Cato Auestad
Related protips
2 Responses
This is secure to use in productions app?
over 1 year ago
·
Depends on your use, I guess.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Cookies
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#