What are cookies and how to use Cookies in angular 2?

Cookies are packages of information that are stored by the browser from websites that use cookies for multiple uses.

There are two ways to create cookies:

  • Inject service in components providers.
  • Get it via npm.



Here is the example of one ng2-cookies.

import { Cookie } from 'ng2-cookies/ng2-cookies';

Cookie.setCookie('cookieName', 'cookieValue');
Cookie.setCookie('cookieName', 'cookieValue', 5);
Cookie.setCookie('cookieName', 'cookieValue', 5, '/app/', 'bestinterviewquestion.com');

let myCookie = Cookie.getCookie('cookieName');


Suggest An Answer

No suggestions avaliable!

Latest post from Angular 2 Interview Questions

Ask Question