Angular Cookie read and write operation code

Angular Cookie read and write operation code

Angular Cookie read and write operations, the code is as follows:

var app = angular.module('Mywind',['ui.router'])
app.controller('Myautumn',function($scope,$http,$filter){
//angular Cookie write//Usage: $scioe.addCookie("name", value, time,"/")
$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 reading //Usage: $scope.getCookieValue("name")
  $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 "";
    }
  };
})

This is the end of this article about Angular Cookie reading and writing operation code. For more relevant Angular Cookie reading and writing content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Cookie reading and writing methods in angular
  • AngularJS Getting Started Tutorial: Cookies Read and Write Operation Examples

<<:  Summary of various methods of implementing article dividing line styles with CSS

>>:  How to center your HTML button

Recommend

How to connect to docker server using ssh

When I first came into contact with docker, I was...

Vue implements accordion effect

This article example shares the specific code of ...

vue3 custom directive details

Table of contents 1. Registering custom instructi...

Complete steps to use samba to share folders in CentOS 7

Preface Samba is a free software that implements ...

How to implement rounded corners with CSS3 using JS

I found an example when I was looking for a way t...

Installation of mysql-community-server. 5.7.18-1.el6 under centos 6.5

Use the following command to check whether MySQL ...

How to change the MySQL database file directory in Ubuntu

Preface The company's Ubuntu server places th...

Detailed explanation of HTML style tags and related CSS references

HTML style tag style tag - Use this tag when decl...

Vue+Router+Element to implement a simple navigation bar

This project shares the specific code of Vue+Rout...

Example test MySQL enum type

When developing a project, you will often encount...

WeChat applet realizes the effect of swiping left to delete list items

This article shares the specific code for WeChat ...

JavaScript to achieve the effect of clicking on the self-made menu

This article shares the specific code of JavaScri...

Nginx rush purchase current limiting configuration implementation analysis

Due to business needs, there are often rush purch...

XHTML Basic 1.1, a mobile web markup language recommended by W3C

W3C recently released two standards, namely "...