码迷,mamicode.com
首页 > 其他好文 > 详细

Angular Cookie 读写

时间:2018-01-23 21:18:05      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:读写   time   control   filter   姓名   scope   ring   lte   dex   

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 读写

标签:读写   time   control   filter   姓名   scope   ring   lte   dex   

原文地址:https://www.cnblogs.com/wr1994/p/8337835.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!