我是靠谱客的博主 疯狂美女,这篇文章主要介绍Angular Cookie 读写操作代码,现在分享给大家,希望可以做个参考。

Angular Cookie 读写操作,代码如下所示:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var app = angular.module('Mywind',['ui.router']) app.controller('Myautumn',function($scope,$http,$filter){ //angular Cookie写 //用法 :$scioe.addCookie("姓名",值,时间,"/") $scope.addCookie = function(name, value, days, path) {   var name = decodeURI(name);   var value = decodeURI(value);   var expires = new Date();   expires.setTime(expires.getTime() + days * 3600000 * 24);   path = path == "" ? "" : ";path=" + path;   var _expires = (typeof days) == "string" ? "" : ";expires=" + expires.toUTCString();   document.cookie = name + "=" + value + _expires + path; } //angular Cookie读 //用法:$scope.getCookieValue("姓名")   $scope.getCookieValue = function(name) {     var name = decodeURI(name);     var allcookies = document.cookie;     name += "=";     var pos = allcookies.indexOf(name);     if(pos != -1) {       var start = pos + name.length;       var end = allcookies.indexOf(";", start);     if(end == -1) end = allcookies.length;       var value = allcookies.substring(start, end);       return(value);     } else {       return "";     }   }; })

到此这篇关于Angular Cookie 读写操作代码的文章就介绍到这了,更多相关Angular Cookie 读写内容请搜索靠谱客以前的文章或继续浏览下面的相关文章希望大家以后多多支持靠谱客!

最后

以上就是疯狂美女最近收集整理的关于Angular Cookie 读写操作代码的全部内容,更多相关Angular 内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(403)

评论列表共有 0 条评论

立即
投稿
返回
顶部