0

I trying to set a cookie following this approach. However I must have missed something fundamental as the console only returns undefined. Here is the full html content.

<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular-cookies.js"></script>

<script>
    angular.module('App', ['ngCookies'])
    .controller('ctrl', ['$cookies', function($cookies) {
        $cookies.put('token', 'Test', {'expires': 'Fri, 31 Dec 9999 23:59:59'});
        console.log($cookies.get('token'));
    }]);
</script>

</head>
<body ng-app="App" ng-controller="ctrl"></body>
</html>

For the off-case it matters: Chromium 65 on Ubuntu 16.04 (64-bit). Thank you for your help.

Daniel W Strimpel
  • 8,190
  • 2
  • 28
  • 38
magu_
  • 4,766
  • 3
  • 45
  • 79

1 Answers1

1

Nothing wrong in your code with the way to set cookies. Actually Chrome ignores cookies from local pages but other browsers like safari will satisfy you with it's execution. If you upload the page to remote server, it will work for chromium. So It is better use localStorage instead of cookies in your case.

Sunny
  • 577
  • 6
  • 20
  • Interesting, I didn't know that. For more "Reasons": https://bugs.chromium.org/p/chromium/issues/detail?id=535 – magu_ Apr 19 '18 at 22:25