使用 angular 保存 cookie 4
Saving cookie using angular 4
我有一个基于 ldap 的身份验证,如果用户凭据匹配,则会收到承载令牌和用户 ID 作为 JSON 格式的响应。现在我需要将这些值保存在 cookie 中。我正在使用 angular 4。我找不到 angular 4.
的任何 cookie 相关示例
我知道回答这个问题有点晚了,但您可以使用 ngx-cookie-service 节点包来解决这个问题。
1.安装
npm install ngx-cookie-service --save
2。然后将 cookie 服务作为提供商添加到您的 app.module.ts:
@NgModule({
...,
providers: [ CookieService ]
})
3。然后,将其导入并注入到一个组件中:
import { CookieService } from 'ngx-cookie-service';
constructor( private cookieService: CookieService ) { }
ngOnInit(): void {
this.cookieService.set( 'Test', 'Hello World' );
this.cookieValue = this.cookieService.get('Test');
}
4.一切就绪
我有一个基于 ldap 的身份验证,如果用户凭据匹配,则会收到承载令牌和用户 ID 作为 JSON 格式的响应。现在我需要将这些值保存在 cookie 中。我正在使用 angular 4。我找不到 angular 4.
的任何 cookie 相关示例我知道回答这个问题有点晚了,但您可以使用 ngx-cookie-service 节点包来解决这个问题。
1.安装
npm install ngx-cookie-service --save
2。然后将 cookie 服务作为提供商添加到您的 app.module.ts:
@NgModule({
...,
providers: [ CookieService ]
})
3。然后,将其导入并注入到一个组件中:
import { CookieService } from 'ngx-cookie-service';
constructor( private cookieService: CookieService ) { }
ngOnInit(): void {
this.cookieService.set( 'Test', 'Hello World' );
this.cookieValue = this.cookieService.get('Test');
}
4.一切就绪