Angular Cookie 讀寫操作代碼
更新時間:2022年01月05日 11:57:07 作者:飛翔的小倉鼠
這篇文章主要介紹了Angular Cookie 讀寫操作代碼,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,感興趣的朋友跟隨小編一起看看吧
Angular Cookie 讀寫操作,代碼如下所示:
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 "";
}
};
}) 到此這篇關(guān)于Angular Cookie 讀寫操作代碼的文章就介紹到這了,更多相關(guān)Angular Cookie 讀寫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Angular2+國際化方案(ngx-translate)的示例代碼
本篇文章主要介紹了Angular2+國際化方案(ngx-translate)的示例代碼,具有一定的參考價值,有興趣的可以了解一下2017-08-08
詳解如何構(gòu)建Angular項目目錄結(jié)構(gòu)
本篇文章主要介紹了詳解如何構(gòu)建Angular項目目錄結(jié)構(gòu),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07

