AngularJS:不能使用$ cookieStore添加cookie [英] AngularJS: Can not add cookies using $cookieStore

查看:590
本文介绍了AngularJS:不能使用$ cookieStore添加cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用$ cookieStore添加Cookie

I am trying to add cookie using $cookieStore

  $scope.addSession = function() {
    console.log('adding session');
    $cookieStore.put('session', 'value');
    $scope.session= $cookieStore.get('session');
  };

但它失败,出现以下错误

But it fails with the following error

Error: Can't find variable: $cooki
addSession@http://run.plnkr.co/61uMvzWlbCCsHRYM/script.js:8
@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:6365
@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:12987
$eval@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8057
$apply@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8137
@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:12988
dispatch@http://code.jquery.com/jquery-2.0.3.min.js:5
handle@http://code.jquery.com/jquery-2.0.3.min.js:5
[native code]

演示/代码可以在这里

请让我知道我在做什么错误在这里

Please let me know what I am doing wrong here

推荐答案

问题是页面刷新,它在我刷新页面后开始工作。

The problem was page refresh, it started to work after I refreshed the page.

请头以上工作代码 rel=\"nofollow\">

Please head over to working code here

这篇关于AngularJS:不能使用$ cookieStore添加cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆