When I check the console, my code is printing:
[Object, Object]
I am having trouble drilling down into the objects.
I have attempted to use JSON.Parse and JSON.stringify without any luck.
The service responsible for setting credentials:
setCredentials.js
'use strict';
// This service manages setting and getting cookies
app.service('setCredentials', function($cookies) {
// Function that takes a JSON object and stores it within a cookie
this.storeInCookie = function(responseObject) {
console.log(responseObject);
// Set the cookie
var cookieObj = {
currentUser: {
userType: responseObject.auth.userType,
username: responseObject.auth.email,
token: responseObject.auth.token
}
};
console.log(cookieObj);
// Set up header, in case we need auth token inside it for later
//$http.defaults.headers.common['Authorization'] = 'Basic ' + authdata;
// Store the data inside the cookie
$cookies.put('globals', cookieObj);
return true;
};
// Function to remove the cookie
this.removeCookie = function() {
};
// Function to retrieve the cookie
this.getCookie = function(cookieName) {
// Get the cookie
return $cookies.get(cookieName);
};
});
Then, I access the cookie object in a controller:
navigationController.js
'use strict';
// Global variables for the app
// This controller handles post requests
// Declaring dependencies like $http, $location, custom service apiServiceWeb
app.controller('navigationController', function($scope, $rootScope, $http, $location, $cookies, setCredentials) {
// Navigation menu
// Get the content of the cookie
var cookieValue = setCredentials.getCookie('globals');
console.log($cookies.get('globals'));
});