我在Cookie上存储用户对象,当客户端再次访问该站点时,我想使用此对象的属性。
但是,当客户端回来时,我的cookie对象看起来像[object object]
,而它的属性看起来像undefined
。
这里是我的代码:
$scope.signup = function (user) {
$http.post('/api/signup', user)
.then(function (res) {
$cookies.put('user', res.data.user); //This is where I store my cookie.
}, function (res) {
});
};
当客户端回来,我有这样的代码:
var lastUser = $cookies.get('user');
if (lastUser) $scope.lastName = lastUser.username;
console.log(lastUser); // [object object]
console.log(lastName); // undefined
我能做些什么,以获得正确的饼干信息?
存储对象的cookie是一个坏主意。使用本地存储。 – epascarello
感谢您的回答。你能告诉我为什么吗? – Rodmentou
http://stackoverflow.com/questions/3220660/local-storage-vs-cookies – epascarello