Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$cookies object has no properties

I'm trying to use the $cookies service using angular 1.4.0-beta.2.

The cookie created by the server gets into document.cookie and also into $cookies. but $cookies is just a simple object. when I check console.dir($cookies) there's only keys/values inside. where's the get(), put(), getAll()functions?

I've tried to check the very basic sample code from https://docs.angularjs.org/api/ngCookies/service/$cookies :

    angular.module('cookiesExample', ['ngCookies'])
       .controller('ExampleController', ['$cookies', function($cookies) {
           // Retrieving a cookie
           var favoriteCookie = $cookies.get('myFavorite');
           // Setting a cookie
           $cookies.put('myFavorite', 'oatmeal');
       }]);

but it doesn't work. It's probably trivial, but what am I missing?

like image 317
yaron hochman Avatar asked Mar 09 '15 12:03

yaron hochman


1 Answers

did you remember to update "angular-cookies" too? it's a plugin, so updating "angular" alone won't work.

I'm using 1.4.0-rc.1, and it works (having updated "angular-cookies" to "1.4.0-rc.1", of course)

like image 89
tommyTheHitMan Avatar answered Nov 08 '22 22:11

tommyTheHitMan