I have a ldap based authentication in place where if the user credentials are matched , a bearer token and an userId is received as a response in JSON format. Now I need to save these values in cookie. I am using angular 4. I could not find any cookie related example for angular 4.
To save information in the cookies you will need to use set() function. It takes two parameters: the name of the key and the value of the key. The get() function is used to get a single value from a cookie. To get all values, you can use the getAll() function.
AngularJS uses ngCookies module and $cookieStoreservice to carry out the various functions of reading, writing and removing Cookies. The below HTML Markup consists of an HTML DIV to which ng-app and ng-controller AngularJS directives have been assigned.
Angular service to read, set and delete browser cookies. Originally based on the ng2-cookies library. The experienced team behind Studytube will take care of our cookie service from now on.
I know it's a bit late to answer this but you can use ngx-cookie-service node package for it.
1. Install
npm install ngx-cookie-service --save
2. Then add the cookie service to your app.module.ts as a provider:
@NgModule({
...,
providers: [ CookieService ]
})
3. Then, import and inject it into a component:
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. You are all set
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