How can you work with cookies in Angular?
To work with Cookies, we can make use of the CookieService which is a part of the ngx-cookie-service module.
- Install:
npm install --save ngx-cookie-service
- Include:
import { CookieService } from 'ngx-cookie-service';
@NgModule({
providers: [ CookieService ],
})
export class AppModule { }
- Use:
constructor( private cookieService: CookieService ) {
this.cookieService.set( 'MyCookieKey', 'Hello There!' );
this.cookieValue = this.cookieService.get('Test');
}