app.controller('appCtrl', function ($scope, $cookieStore) {
$scope.$watch(function(){return $cookieStore.get('currentUser');}, function(newValue, oldValue){
if(newValue !== oldValue){
$scope.currentUser = $cookieStore.get('currentUser');
}
});
});
我开发了上面的代码,目的是观察保存在$ cookieStore中的值。当用户成功烧录时,json对象将保存在$ cookieStore中,借助此$ watch函数,用户信息将显示在页面的顶角。
$cookieStore.put('currentUser', response);
我对这个解决方案有两个问题:
如果我改变我的解决方案使用$ cookies而不是$ cookieStore,它似乎都按预期工作,但$ cookies不允许我保存Json对象,这就是我更喜欢使用$ cookieStore的原因。
有什么想法吗?非常感谢!