ngx cookie

 cookies:

data store

ng new cookies


ng serve --port 4100 -o

npm install ngx-cokie-service


import cookie service

in module

app module:

import  {cookieService}

from 'ngx cookie services'

providers:[cookieService]




inject cookie service

in component

:--

import {cookieService}

from 'ngx-cookie-service';

constructor(private

cookie:cookieService){


}

setCookie(){

this.cookie.set("key","value")


}


getCookie(){

console.log(this.cookie.get("key");

}


removeCookie(){

this.cookie.delete('key');}

removeallCookie(){

this.cookie.deleteAll();

}


html:

<button (click)=

"setCookie()">setCookie</button>

<button (click)=

"getCookie()">getCookie</button>

.................

<button (click)=

"removeCookie()">removeCookie</button>


<button (click)=

"removeallCookie()">removeallCookie</button>











set cookie

get cookie

remove cookie

clear all cookie








Comments

Popular posts from this blog

interview questions js[ Anurag Singh ProCodrr]

reactnative_creation