1

I'm using AngularJS $cookies 1.6.9 to manage cookies on my website. I've tried a simple cookie set, as follows:

$cookies.put('myCookieTest', 'test');
var cookie = $cookies.get('myCookieTest');
console.log(cookie);

I've installed angular-cookies correctly and no error is returned in the console when I set or retrieve the cookie. Though the result of this code snippet is undefined. In the Google Chrome inspector, unde the Application tab, in the cookies section I don't see my cookie so it seems the code doesn't set it.

Any idea on what I'm missing here or what is wrong with the code?

Leonardo Minati
  • 360
  • 1
  • 4
  • 17

2 Answers2

0

Ensure that you injected ngCookies in your module and your controller. Please check this simple demo fiddle and compare it with your solution. Also ensure that you are using the right version of ngCookies. ngCookies 1.6.9 was made for AngularJS version 1.6.9.

var myApp = angular.module("myApp", ['ngCookies']);

myApp.controller("Ctrl1", function($$cookies) {
  $cookies.put('myCookieTest', 'test');
  var cookie = $cookies.get('myCookieTest');
  console.log(cookie);
});
lin
  • 17,956
  • 4
  • 59
  • 83
0

please check version

Hi,

I think you have configured all things well but might be version issue.

Santosh Singh
  • 561
  • 2
  • 16