I am using ngx-cookie-service package
{
"user": [
{
"id": 109,
"name": "name1",
"job" : "job name"
}
],
"token":"xxxx"
}
this.cookieService.set( 'user_id', result.user.id );
this.cookieService.set( 'user_name', result.user.name );
this.cookieService.set( 'user_job', result.user.job );
How can I save this as a JSON array instead of saving individual?
like this.cookieService.set( 'user', result.user );
You can use stringify() and save it and then parse() to get the value back
To set the value:
this.cookieService.set('user', JSON.stringify(result));
To retrieve the value:
JSON.parse(this.cookieService.get('user'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With