Reputation: 2187
Update: When I posted this question, I had been executing the code directly from my desktop. I just put my cookie sample into some angular code running in my localhost server, and I can now successfully create and read cookies from all browsers: Chrome, IE, and Firefox. Are there rules that Chrome follows in regards to creating/reading cookies when code is not being served up from a server?
Original question: I've created a very simple angularjs application, trying to use make use of angular cookies, and although it works in Firefox and IE, it doesn't seem to work in Chrome.
Here is my html code:
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular-cookies.js"></script>
<script src="js/cookieApp.js"></script>
</head>
<body ng-controller="mainCtrl">
</body>
</html>
Here is my angular code:
(function () {
angular.module('myApp', ['ngCookies'])
.controller('mainCtrl', ['$cookies', function($cookies) {
$cookies.put('myFavorite', "cheese");
var favoriteCookie = $cookies.get('myFavorite');
console.log("myFavorite = " + favoriteCookie);
}]);
})();
When I run this code from Firefox and IE, I can see in the console log:
myFavorite = cheese
However, when I run this in Chrome, I see this in the console log:
myFavorite = undefined
The version of Chrome that I'm using is "Version 65.0.3325.181 (Official Build) (64-bit)".
Am I doing something wrong here or is there a setting in Chrome that needs to be adjusted to allow cookies?
Upvotes: 2
Views: 1085