zoukankan      html  css  js  c++  java
  • Angular cookies

    参考地址:https://stackoverflow.com/questions/34298133/angular-cookies/36093800#36093800

    @Component({
        selector: 'cookie-consent',
        template: cookieconsent_html,
        styles: [cookieconsent_css]
    })
    export class CookieConsent {
        private isConsented: boolean = false;
    
        constructor() {
            this.isConsented = this.getCookie(COOKIE_CONSENT) === '1';
        }
    
        private getCookie(name: string) {
            let ca: Array<string> = document.cookie.split(';');
            let caLen: number = ca.length;
            let cookieName = `${name}=`;
            let c: string;
    
            for (let i: number = 0; i < caLen; i += 1) {
                c = ca[i].replace(/^s+/g, '');
                if (c.indexOf(cookieName) == 0) {
                    return c.substring(cookieName.length, c.length);
                }
            }
            return '';
        }
    
        private deleteCookie(name) {
            this.setCookie(name, '', -1);
        }
    
        private setCookie(name: string, value: string, expireDays: number, path: string = '') {
            let d:Date = new Date();
            d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000);
            let expires:string = `expires=${d.toUTCString()}`;
            let cpath:string = path ? `; path=${path}` : '';
            document.cookie = `${name}=${value}; ${expires}${cpath}`;
        }
    
        private consent(isConsent: boolean, e: any) {
            if (!isConsent) {
                return this.isConsented;
            } else if (isConsent) {
                this.setCookie(COOKIE_CONSENT, '1', COOKIE_CONSENT_EXPIRE_DAYS);
                this.isConsented = true;
                e.preventDefault();
            }
        }
    }
  • 相关阅读:
    IDEA service/DashBoard 不显示服务端口号
    是否同一棵二叉搜索树
    Tree Traversals Again
    有符号数移位
    tl431基准的用法
    7寸屏电压方案
    test
    合并commit
    重命名commit
    Git 在公司内部的使用规范
  • 原文地址:https://www.cnblogs.com/zxyun/p/8932546.html
Copyright © 2011-2022 走看看