6
सांत्वना मेरी कोड में मुद्रण है।जोड़ना json वस्तु कोणीय जे एस
मैं JSON.parse और की कोशिश की है JSON.stringify सफलता नहीं मिली।
मेरी सेवा है कि साख सेट:
setCredentials.js
'use strict';
// service that handles setting and getting cookies
app.service('setCredentials', function($cookies) {
// function that gets json object and stores it inside 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 inside of cookie
$cookies.put('globals', cookieObj);
return true;
};
//function to remove cookie
this.removeCookie = function() {
};
//function to get cookie
this.getCookie = function(cookieName) {
//get cookie
return $cookies.get(cookieName);
};
});
मैं तो एक नियंत्रक में कुकी वस्तु फोन:
navigationController.js
'use strict';
//app global variable
//this is the controller that handles post requests
//declare services as dependecies $http, $location, custom service apiServiceWeb
app.controller('navigationController', function($scope, $rootScope, $http, $location, $cookies, setCredentials) {
//navigation menu
//get what is in the cookie
var cookieValue = setCredentials.getCookie('globals');
console.log($cookies.get('globals'));
});
कृपया अपनी सेवा घोषणा में '$ लॉग' [निर्भरता] (https://docs.angularjs.org/api/ng/service/$log) जोड़ें:' app.service ('setCredentials', function ($ कुकीज़, $ लॉग) ... ', तो आप उन्नत लॉगिंग का उपयोग कर सकते हैं, जैसे: '$ log.debug (respondObject);' उम्मीद है कि यह मदद करता है। – barfoos