Carlos Cifuentes
AngularJS library migration · cookies

Migrating ngCookies ($cookies) to modern Angular

ngCookies provided the $cookies service (and the older $cookieStore) to read and write browser cookies, with putObject and getObject for JSON values.

What replaces it

OptionWhen to choose it
ngx-cookie-serviceA maintained service with get, set, check and delete.
A small CookieService of your ownA few lines over document.cookie when you read or write one or two cookies.
HttpOnly cookies set by the serverFor session tokens: JavaScript should not read them at all.

How to migrate it

  1. List every cookie the frontend reads or writes, with its path, domain and expiry.
  2. Create a CookieService in Angular and use it from both frameworks through downgrade.
  3. Move anything that the server does not need out of cookies and into localStorage or memory.

Watch out. A cookie written with a different path or domain does not replace the old one; it creates a second cookie with the same name. Keep the same attributes during the hybrid phase.

Other libraries

Planning a migration or a micro-frontend platform?

In a 20-minute call you describe your situation and I tell you how I'd approach it. If it isn't worth doing yet, I'll say so.

Message me on LinkedIn