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
| Option | When to choose it |
|---|---|
| ngx-cookie-service | A maintained service with get, set, check and delete. |
| A small CookieService of your own | A few lines over document.cookie when you read or write one or two cookies. |
| HttpOnly cookies set by the server | For session tokens: JavaScript should not read them at all. |
How to migrate it
- List every cookie the frontend reads or writes, with its path, domain and expiry.
- Create a CookieService in Angular and use it from both frameworks through downgrade.
- 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