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

Several magical uses of JS ES6 spread operator

Table of contents 1. Add attributes 2. Merge mult...

Example of how rem is adapted for mobile devices

Preface Review and summary of mobile terminal rem...

Detailed explanation of how Node.js middleware works

Table of contents What is Express middleware? Req...

Summary of MySQL development standards and usage skills

1. Naming conventions 1. Database names, table na...

Database SQL statement optimization

Why optimize: With the launch of the actual proje...

How to point the target link of a tag to iframe

Copy code The code is as follows: <iframe id=&...

js+Html to realize table editable operation

This article shares the specific code of js+Html ...

A brief analysis of Linux network programming functions

Table of contents 1. Create a socket 2. Bind sock...

Let's talk about the difference between MyISAM and InnoDB

The main differences are as follows: 1. MySQL use...

How to install Django in a virtual environment under Ubuntu

Perform the following operations in the Ubuntu co...

Detailed explanation of mysql permissions and indexes

mysql permissions and indexes The highest user of...

Analysis of Apache's common virtual host configuration methods

1. Apache server installation and configuration y...

Front-end development must learn to understand HTML tags every day (1)

2.1 Semanticization makes your web pages better u...

Superficial Web Design

<br />I have always believed that Yahoo'...

Detailed explanation of Linux file operation knowledge points

Related system calls for file operations create i...