Angular6操作cookie

年凯康
2023-12-01

Angular提供ngx-cookie-service来操作cookie

1、首先,安装ngx-cookie-service

npm install ngx-cookie-service

app.module.ts

import { CookieService } from 'ngx-cookie-service';
@NgModule({
  imports: [], 
  providers: [
    CookieService  //注入服务
  ]
})

app.component.ts

import { CookieService } from 'ngx-cookie-service';

constructor(private cookieService: CookieService) {
  }
//cookie的存储
this.cookieService.set('type', type);
//cookie的读取
const type= this.cookieService.get("type");

 类似资料: