角和饼干$ - $ cookies.get不是一个函数 [英] Angular and $cookies - $cookies.get is not a function

查看:124
本文介绍了角和饼干$ - $ cookies.get不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图角范围内使用Cookie - 在这里就是我想:

I'm trying to use cookies within Angular - here's what I'm trying:

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular-cookies.min.js"></script>

var capApp = angular.module('capApp', ['ngRoute','ui.bootstrap','ngCookies']);

capApp.controller('cookieCtrl', ['$scope','$cookies', function($scope, $cookies) {
  var favoriteCookie = $cookies.get('user_id');
  alert(favoriteCookie);
}]);

我得到在控制台这个错误:

I get this error in the console:

TypeError: $cookies.get is not a function

任何想法,我要去哪里错了?

Any ideas where I'm going wrong?

更新

检查您所使用的一切角的版本 - 任意角度的家伙阅读,请在文档明亮的绿色和庞大的版本切换!你根本就不会注意到它。

Check which version of Angular you are using for everything - any Angular guys read this, make the version switch in the docs bright green and huge! You simply don't notice it.

推荐答案

在角1.3.14你可以只用

In Angular 1.3.14 you can just use

var favoriteCookie = $cookies[user_id];

在这里见载文:角饼干

这篇关于角和饼干$ - $ cookies.get不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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