CookieService
✓ Published0🌍 Public
Aackuser
Last edited Jan 5, 2019
Created on Jan 31, 2019
This example shows an Angular service class, `CookieService`, that provides typed methods for setting and retrieving browser cookies. It demonstrates a fluent API for specifying cookie expiration in units from milliseconds up to years, converting the requested duration into a `Date` object and calling `document.cookie` to persist the value. The `get` method decodes the cookie string, splits it into key-value pairs, and returns the value for the requested key, or an empty string if absent. The code relies solely on the browser’s native `document.cookie` API and Angular’s `Injectable` decorator.
AI-generated description