Angular 和 $cookies - $cookies.get 不是函数 [英] Angular and $cookies - $cookies.get is not a function
本文介绍了Angular 和 $cookies - $cookies.get 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Angular 中使用 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?
更新
检查您正在使用哪个版本的 Angular - 任何阅读此内容的 Angular 人员,请在文档中切换为亮绿色和巨大的版本!你根本没有注意到.
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.
推荐答案
在 Angular 1.3.14 中你可以直接使用
In Angular 1.3.14 you can just use
var favoriteCookie = $cookies[user_id];
在此处查看文档:Angular Cookies
这篇关于Angular 和 $cookies - $cookies.get 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文