I am relatively new to working with Angular. I have started a test project and my goal is to store user authentication in cookies. Despite my best efforts, I keep encountering an undefined error when attempting to retrieve the stored value. I am not sure what exactly is wrong as I have followed the steps diligently and searched through various responses on stackoverflow. Thank you for any insights you may provide.
I have also enabled Chrome cookies to read and write data by following this link: https://i.stack.imgur.com/Bh3fr.png
Currently using Angular version 1.6.6
angular.module('LoginCtrl', ["ngCookies"])
.controller('LoginController', function($rootScope, $location, $scope,
$http, $cookies)
{
$scope.loginformData = {};
$scope.loginmessage='';
$scope.errorlogin=false;
$scope.loginUser = function()
{
Login.login($scope.loginformData)
.then(function(data)
{
$scope.loginmessage = data;
if(data!=='Wrong Email Or Password!')
{
$cookies.put('myFavorite', 'oatmeal');
var favoriteCookie = $cookies.get('myFavorite');
console.log(favoriteCookie); // returns undefined
}
else
{
$scope.errorlogin = true;
console.log('Error');
}
});
};
});
<script src="https://code.angularjs.org/1.6.6/angular.js"></script>
<script src="https://code.angularjs.org/1.6.6/angular-cookies.js"></script>
<base href="/index.html"/>
<div ng-app="LoginCtrl">
<div ng-controller="LoginController">
</div>
</div>