### Install NGX Cookie Service Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/README.md Installs the ngx-cookie-service library using either npm or yarn. ```bash npm i ngx-cookie-service # or yarn add ngx-cookie-service ``` -------------------------------- ### Install NGX Cookie Service Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service-ssr/README.md Installs the NGX Cookie Service package using either npm or yarn. ```bash npm install ngx-cookie-service --save # or yarn add ngx-cookie-service ``` -------------------------------- ### Install ngx-cookie-service-ssr for SSR Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service-ssr/README.md Installs the ngx-cookie-service-ssr library, which is required for Server Side Rendering with the NGX Cookie Service. ```shell npm install ngx-cookie-service-ssr --save # or yarn add ngx-cookie-service-ssr ``` -------------------------------- ### Get All Cookies API Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service/README.md Retrieves all accessible cookies as a key-value map. ```APIDOC ## GET /api/cookie/getAll ### Description Returns a map of key-value pairs for cookies that can be accessed. ### Method GET ### Endpoint `/api/cookie/getAll` ### Response #### Success Response (200) - **cookies** (object) - An object where keys are cookie names and values are their corresponding cookie values. ### Response Example ```json { "cookies": { "cookie1": "value1", "cookie2": "value2" } } ``` ``` -------------------------------- ### Get All Cookies Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/README.md Retrieves all accessible cookies as a key-value map. ```APIDOC ## getAll(): {} ### Description Returns a map of key-value pairs for cookies that can be accessed. ### Method GET ### Endpoint N/A (This is a client-side method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript const allCookies: {} = cookieService.getAll(); ``` ### Response #### Success Response ({}) - **map**: An object where keys are cookie names and values are cookie string values. #### Response Example ```json { "cookieMap": { "sessionID": "abc123xyz", "preferences": "theme=dark&lang=en" } } ``` ``` -------------------------------- ### Usage in Standalone Components (Angular) Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/README.md Demonstrates how to import and use the CookieService in Angular standalone components, including setting and getting a cookie. ```typescript import { CookieService } from 'ngx-cookie-service'; import { Component } from '@angular/core'; @Component({ selector: 'my-component', template: `

Hello World

`, providers: [CookieService], }) export class HelloComponent { constructor(private cookieService: CookieService) { this.cookieService.set('token', 'Hello World'); console.log(this.cookieService.get('token')); } } ``` -------------------------------- ### Cookie Get API Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service/README.md Retrieves the value of a cookie by its name. ```APIDOC ## GET /api/cookie/get ### Description Gets the value of the cookie with the specified `name`. ### Method GET ### Endpoint `/api/cookie/get/{name}` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the cookie to retrieve. ### Response #### Success Response (200) - **value** (string) - The value of the specified cookie. ### Response Example ```json { "value": "cookie_value" } ``` ``` -------------------------------- ### Get All Cookies Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service-ssr/README.md Retrieves all accessible cookies as a key-value map. ```APIDOC ## GET /api/cookies ### Description Returns a map of key-value pairs for cookies that can be accessed. ### Method GET ### Endpoint `/api/cookies` ### Response #### Success Response (200) - **cookies** ({}) - An object where keys are cookie names and values are their corresponding cookie values. ### Response Example ```json { "cookies": { "cookie1": "value1", "cookie2": "value2" } } ``` ``` -------------------------------- ### Inject and Use CookieService in Component Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service-ssr/README.md Injects the CookieService into a component's constructor and demonstrates setting and getting a cookie. ```typescript constructor(private cookieService: CookieService ) { this.cookieService.set('Test', 'Hello World'); this.cookieValue = this.cookieService.get('Test'); } ``` -------------------------------- ### Get All Cookies with ngx-cookie-service Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service/README.md Returns all accessible cookies as a key-value map. This method does not take any arguments and returns an object containing all available cookies. ```typescript const allCookies: {} = cookieService.getAll(); ``` -------------------------------- ### Get Cookie Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/README.md Retrieves the value of a cookie associated with the provided name. ```APIDOC ## get(name: string): string ### Description Gets the value of the cookie with the specified `name`. ### Method GET ### Endpoint N/A (This is a client-side method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript const value: string = cookieService.get('test'); ``` ### Response #### Success Response (string) - **value**: The string value of the cookie. #### Response Example ```json { "cookieValue": "Hello World" } ``` ``` -------------------------------- ### Get Cookie Value Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service-ssr/README.md Retrieves the value of a specified cookie. ```APIDOC ## GET /api/cookie/{name} ### Description Gets the value of the cookie with the specified name. ### Method GET ### Endpoint `/api/cookie/{name}` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the cookie to retrieve. ### Response #### Success Response (200) - **value** (string) - The value of the cookie. ### Response Example ```json { "value": "Hello World" } ``` ``` -------------------------------- ### Get Cookie Value with ngx-cookie-service Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service/README.md Retrieves the value of a cookie identified by its name. This method accepts the cookie name as a string and returns the cookie's value as a string. ```typescript const value: string = cookieService.get('test'); ``` -------------------------------- ### Reinstall Node Modules with Yarn or NPM Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service/README.md Resolves 'token missing' or 'no provider' errors by removing the node_modules directory and reinstalling dependencies using either Yarn or NPM. ```shell rm -rf node_modules yarn # or `npm install` ``` -------------------------------- ### Set Cookie with ngx-cookie-service Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service/README.md Sets a cookie with a specified name and value, with optional parameters for expiration, path, domain, security, and sameSite attribute. It is recommended to specify a path, typically '/'. The 'secure' flag is automatically set to true if 'sameSite' is 'None'. ```typescript cookieService.set('test', 'Hello World'); cookieService.set('test', 'Hello World', { expires: 2, sameSite: 'Lax' }); ``` -------------------------------- ### Set Cookie Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/README.md Sets a cookie with the specified name and value. Supports optional expiration, path, domain, secure flag, and sameSite attribute. ```APIDOC ## POST /cookie ### Description Sets a cookie with the specified name and value. It is good practice to specify a path. If you are unsure about the path value, use '/' . If no path or domain is explicitly defined, the current location is assumed. `sameSite` defaults to `Lax`. **Important:** For security reasons, it is not possible to define cookies for other domains. Browsers do not allow this. **Important:** Browsers do not accept cookies flagged sameSite = 'None' if secure flag isn't set as well. CookieService will override the secure flag to true if sameSite='None'. ### Method POST ### Endpoint /cookie ### Parameters #### Request Body - **name** (string) - Required - The name of the cookie. - **value** (string) - Required - The value of the cookie. - **options** (object) - Optional - An object containing cookie options. - **expires** (number | Date) - Optional - The expiration date or time in days. - **path** (string) - Optional - The path for the cookie. - **domain** (string) - Optional - The domain for the cookie. - **secure** (boolean) - Optional - Whether the cookie should be secure. - **sameSite** ('Lax' | 'Strict' | 'None') - Optional - The sameSite attribute for the cookie. ### Request Example ```json { "name": "test", "value": "Hello World", "options": { "expires": 2, "sameSite": "Lax" } } ``` ### Response #### Success Response (200) - **message** (string) - Indicates the cookie was set successfully. #### Response Example ```json { "message": "Cookie 'test' set successfully." } ``` ``` -------------------------------- ### Usage with inject() (Angular v14+) Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/README.md Shows how to inject the CookieService using the `inject()` function in Angular components (v14 and later). ```typescript import { CookieService } from 'ngx-cookie-service'; import { Component, inject } from '@angular/core'; @Component({ selector: 'my-component', template: `

Hello World

`, providers: [CookieService], }) export class HelloComponent { cookieService = inject(CookieService); constructor() { this.cookieService.set('token', 'Hello World'); console.log(this.cookieService.get('token')); } } ``` -------------------------------- ### Set Cookie API Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service/README.md Sets a cookie with a specified name, value, and optional configuration. ```APIDOC ## POST /api/cookie/set ### Description Sets a cookie with the specified `name` and `value`. Optional parameters include `expires`, `path`, `domain`, `secure`, and `sameSite`. ### Method POST ### Endpoint `/api/cookie/set` ### Parameters #### Request Body - **name** (string) - Required - The name of the cookie. - **value** (string) - Required - The value of the cookie. - **options** (object) - Optional - Configuration options for the cookie. - **expires** (number | Date) - Optional - The expiration date or duration in days. - **path** (string) - Optional - The path for the cookie. Defaults to '/'. - **domain** (string) - Optional - The domain for the cookie. - **secure** (boolean) - Optional - Flag to indicate if the cookie should only be transmitted over HTTPS. Automatically set to true if `sameSite` is 'None'. - **sameSite** ('Lax' | 'Strict' | 'None') - Optional - The SameSite attribute for the cookie. Defaults to 'Lax'. ### Request Example ```json { "name": "test", "value": "Hello World", "options": { "expires": 2, "sameSite": "Lax" } } ``` ``` -------------------------------- ### Delete All Cookies with ngx-cookie-service Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service/README.md Deletes all cookies that are currently accessible. Optional parameters for path, domain, security, and sameSite can be provided. It is recommended to specify the path, defaulting to '/'. ```typescript cookieService.deleteAll(); ``` -------------------------------- ### Delete Cookie with ngx-cookie-service Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service/README.md Deletes a specific cookie by its name, with optional parameters for path, domain, security, and sameSite. It is best practice to specify the path, defaulting to '/'. ```typescript cookieService.delete('test'); ``` -------------------------------- ### Configure SSR Server File Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/README.md Modifies the server.ts file in an Angular SSR project to provide request and response objects for cookie handling. ```typescript server.get('*', (req, res) => { res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] }); }); ``` ```typescript server.get('*', (req, res) => { res.render(indexHtml, { req, providers: [ { provide: APP_BASE_HREF, useValue: req.baseUrl }, { provide: 'REQUEST', useValue: req }, { provide: 'RESPONSE', useValue: res }, ], }); }); ``` -------------------------------- ### Delete All Cookies API Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service/README.md Deletes all currently accessible cookies, with optional path and domain parameters. ```APIDOC ## DELETE /api/cookie/deleteAll ### Description Deletes all cookies that can currently be accessed. Optional parameters include `path`, `domain`, `secure`, and `sameSite`. ### Method DELETE ### Endpoint `/api/cookie/deleteAll` ### Parameters #### Request Body - **path** (string) - Optional - The path to filter cookies for deletion. Defaults to '/'. - **domain** (string) - Optional - The domain to filter cookies for deletion. - **secure** (boolean) - Optional - Indicates if the cookies were set with the secure flag. - **sameSite** ('Lax' | 'None' | 'Strict') - Optional - The SameSite attribute of the cookies. Defaults to 'Lax'. ### Request Example ```json { "path": "/" } ``` ``` -------------------------------- ### Set Cookie Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service-ssr/README.md Sets or updates a cookie with specified name, value, and options. ```APIDOC ## POST /api/cookie ### Description Sets a cookie with the specified name and value. It is good practice to specify a path. If no path or domain is explicitly defined, the current location is assumed. `sameSite` defaults to `Lax`. **Important:** For security reasons, it is not possible to define cookies for other domains. Browsers do not allow this. **Important:** Browsers do not accept cookies flagged sameSite = 'None' if secure flag isn't set as well. CookieService will override the secure flag to true if sameSite='None'. ### Method POST ### Endpoint `/api/cookie` ### Parameters #### Request Body - **name** (string) - Required - The name of the cookie. - **value** (string) - Required - The value of the cookie. - **options** (object) - Optional - Configuration options for the cookie. - **expires** (number | Date) - Optional - The expiration date or time in days. - **path** (string) - Optional - The path for the cookie. - **domain** (string) - Optional - The domain for the cookie. - **secure** (boolean) - Optional - Whether the cookie is secure. - **sameSite** ('Lax' | 'Strict' | 'None') - Optional - The SameSite attribute for the cookie. ### Request Example ```json { "name": "test", "value": "Hello World", "options": { "expires": 2, "sameSite": "Lax" } } ``` ``` -------------------------------- ### Delete All Cookies Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/README.md Deletes all cookies that can currently be accessed. It is best practice to always define a path. ```APIDOC ## DELETE /cookie/all ### Description Deletes all cookies that can currently be accessed. It is best practice to always define a path. If you are unsure about the path value, use '/' . ### Method DELETE ### Endpoint /cookie/all ### Parameters #### Query Parameters - **path** (string) - Optional - The path for which to delete cookies. - **domain** (string) - Optional - The domain for which to delete cookies. - **secure** (boolean) - Optional - Whether the cookies are secure. - **sameSite** ('Lax' | 'None' | 'Strict') - Optional - The sameSite attribute for which to delete cookies. Defaults to 'Lax'. ### Request Example ``` DELETE /cookie/all?path=/ ``` ### Response #### Success Response (200) - **message** (string) - Indicates all accessible cookies were deleted. #### Response Example ```json { "message": "All accessible cookies deleted successfully." } ``` ``` -------------------------------- ### Use CookieService with Standalone Components (Angular 14+) Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service-ssr/README.md Demonstrates how to use the CookieService within an Angular standalone component by providing it directly in the component's decorator. ```typescript import { CookieService } from 'ngx-cookie-service'; import { Component } from '@angular/core'; @Component({ selector: 'my-component', template: `

Hello World

`, providers: [CookieService], }) export class HelloComponent { constructor(private cookieService: CookieService) { this.cookieService.set('Test', 'Hello World'); this.cookieValue = this.cookieService.get('Test'); } } ``` -------------------------------- ### Delete Cookie API Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service/README.md Deletes a cookie by its name, with optional path and domain parameters. ```APIDOC ## DELETE /api/cookie/delete ### Description Deletes a cookie with the specified `name`. Optional parameters include `path`, `domain`, `secure`, and `sameSite`. ### Method DELETE ### Endpoint `/api/cookie/delete` ### Parameters #### Request Body - **name** (string) - Required - The name of the cookie to delete. - **path** (string) - Optional - The path of the cookie to delete. Defaults to '/'. - **domain** (string) - Optional - The domain of the cookie to delete. - **secure** (boolean) - Optional - Indicates if the cookie was set with the secure flag. - **sameSite** ('Lax' | 'None' | 'Strict') - Optional - The SameSite attribute of the cookie. Defaults to 'Lax'. ### Request Example ```json { "name": "test", "path": "/" } ``` ``` -------------------------------- ### Cookie Check API Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service/README.md Checks if a cookie with the given name exists and is accessible. ```APIDOC ## GET /api/cookie/check ### Description Checks if a cookie with the given `name` can be accessed or found. ### Method GET ### Endpoint `/api/cookie/check/{name}` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the cookie to check. ### Response #### Success Response (200) - **exists** (boolean) - True if the cookie exists, false otherwise. ### Response Example ```json { "exists": true } ``` ``` -------------------------------- ### Check Cookie Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/README.md Checks if a cookie with the specified name exists and can be accessed. ```APIDOC ## check(name: string): boolean ### Description Checks if a cookie with the given `name` can be accessed or found. ### Method GET ### Endpoint N/A (This is a client-side method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript const cookieExists: boolean = cookieService.check('test'); ``` ### Response #### Success Response (boolean) - **true**: if the cookie exists. - **false**: if the cookie does not exist. #### Response Example ```json { "cookieExists": true } ``` ``` -------------------------------- ### Delete Cookie Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/README.md Deletes a cookie with the specified name. It is best practice to always define a path. ```APIDOC ## DELETE /cookie/{name} ### Description Deletes a cookie with the specified name. It is best practice to always define a path. If you are unsure about the path value, use '/' . **Important:** For security reasons, it is not possible to delete cookies for other domains. Browsers do not allow this. ### Method DELETE ### Endpoint /cookie/{name} ### Parameters #### Path Parameters - **name** (string) - Required - The name of the cookie to delete. #### Query Parameters - **path** (string) - Optional - The path of the cookie to delete. - **domain** (string) - Optional - The domain of the cookie to delete. - **secure** (boolean) - Optional - Whether the cookie is secure. - **sameSite** ('Lax' | 'None' | 'Strict') - Optional - The sameSite attribute of the cookie to delete. Defaults to 'Lax'. ### Request Example ``` DELETE /cookie/test?path=/&domain=example.com ``` ### Response #### Success Response (200) - **message** (string) - Indicates the cookie was deleted successfully. #### Response Example ```json { "message": "Cookie 'test' deleted successfully." } ``` ``` -------------------------------- ### Inject CookieService using inject() (Angular 14+) Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service-ssr/README.md Shows how to inject the CookieService into an Angular component using the `inject()` function, a feature available in Angular 14+. ```typescript import { CookieService } from 'ngx-cookie-service'; import { Component, inject } from '@angular/core'; @Component({ selector: 'my-component', template: `

Hello World

`, providers: [CookieService], }) export class HelloComponent { cookieService = inject(CookieService); constructor() { this.cookieService.set('Test', 'Hello World'); this.cookieValue = this.cookieService.get('Test'); } } ``` -------------------------------- ### Check Cookie Existence with ngx-cookie-service Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service/README.md Checks if a cookie with the specified name exists. It takes the cookie name as a string argument and returns a boolean indicating whether the cookie was found. ```typescript const cookieExists: boolean = cookieService.check('test'); ``` -------------------------------- ### Check Cookie Existence Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service-ssr/README.md Checks if a cookie with the given name exists. ```APIDOC ## GET /api/cookie/{name} ### Description Checks if a cookie with the given name can be accessed or found. ### Method GET ### Endpoint `/api/cookie/{name}` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the cookie to check. ### Response #### Success Response (200) - **exists** (boolean) - True if the cookie exists, false otherwise. ### Response Example ```json { "exists": true } ``` ``` -------------------------------- ### Delete Cookie Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service-ssr/README.md Deletes a cookie by its name, with optional path and domain. ```APIDOC ## DELETE /api/cookie/{name} ### Description Deletes a cookie with the specified name. It is best practice to always define a path. If you are unsure about the path value, use `'/'`. **Important:** For security reasons, it is not possible to delete cookies for other domains. Browsers do not allow this. ### Method DELETE ### Endpoint `/api/cookie/{name}` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the cookie to delete. #### Query Parameters - **path** (string) - Optional - The path of the cookie to delete. - **domain** (string) - Optional - The domain of the cookie to delete. - **secure** (boolean) - Optional - Indicates if the cookie is secure. - **sameSite** ('Lax' | 'None' | 'Strict') - Optional - The SameSite attribute of the cookie. ### Response #### Success Response (204) No content is returned on successful deletion. ``` -------------------------------- ### Delete All Cookies Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service-ssr/README.md Deletes all currently accessible cookies. ```APIDOC ## DELETE /api/cookies ### Description Deletes all cookies that can currently be accessed. It is best practice to always define a path. If you are unsure about the path value, use `'/'`. ### Method DELETE ### Endpoint `/api/cookies` ### Parameters #### Query Parameters - **path** (string) - Optional - The path of the cookies to delete. - **domain** (string) - Optional - The domain of the cookies to delete. - **secure** (boolean) - Optional - Indicates if the cookies are secure. - **sameSite** ('Lax' | 'None' | 'Strict') - Optional - The SameSite attribute of the cookies. ### Response #### Success Response (204) No content is returned on successful deletion. ``` -------------------------------- ### Configure Server.ts for SSR Cookie Access Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service-ssr/README.md Modifies the server.ts file in an SSR project to provide request and response objects, allowing ngx-cookie-service-ssr to access cookies on the server. ```typescript server.get('*', (req, res) => { res.render(indexHtml, { req, providers: [ { provide: APP_BASE_HREF, useValue: req.baseUrl }, { provide: 'REQUEST', useValue: req }, { provide: 'RESPONSE', useValue: res }, ], }); }); ``` -------------------------------- ### Provide CookieService in AppModule Source: https://github.com/stevermeister/ngx-cookie-service/blob/master/projects/ngx-cookie-service-ssr/README.md Adds the CookieService to the providers array in your Angular application's AppModule, making it available throughout the application. ```typescript import {CookieService} from 'ngx-cookie-service'; @NgModule({ ... providers: [CookieService], ... }) export class AppModule { } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.