diff --git a/README.md b/README.md index ee9f492..45e6300 100644 --- a/README.md +++ b/README.md @@ -22,46 +22,21 @@ the [ng2-cookies](https://www.npmjs.com/package/ng2-cookies) library. This servi ## Installation ```bash -npm install ngx-cookie-service --save +npm i ngx-cookie-service # or yarn add ngx-cookie-service ``` -## Usage - -Add the cookie service to your `app.module.ts` as a provider: - -```typescript -import {CookieService} from 'ngx-cookie-service'; - -@NgModule({ - ... - providers:[CookieService], -... -}) - -export class AppModule { -} -``` - -Then, import and inject it into a constructor: +## Demo -```typescript -constructor(private cookieService: CookieService) -{ - this.cookieService.set('Test', 'Hello World'); - this.cookieValue = this.cookieService.get('Test'); -} -``` +https://stackblitz.com/edit/angular-ivy-1lrgdt?file=src%2Fapp%2Fapp.component.ts -That's it! -### Angular 14+ +## Usage -1. Angular 14 introduced support for standalone components. - If you are using just standalone components, you can import the service directly into the component +1. In standalone components, import the CookieService directly into the component ```typescript import { CookieService } from 'ngx-cookie-service'; @@ -74,8 +49,8 @@ That's it! }) export class HelloComponent { constructor(private cookieService: CookieService) { - this.cookieService.set('Test', 'Hello World'); - this.cookieValue = this.cookieService.get('Test'); + this.cookieService.set('token', 'Hello World'); + console.log(this.cookieService.get('token')); } } ``` @@ -95,11 +70,36 @@ That's it! cookieService = inject(CookieService); constructor() { - this.cookieService.set('Test', 'Hello World'); - this.cookieValue = this.cookieService.get('Test'); + this.cookieService.set('token', 'Hello World'); + console.log(this.cookieService.get('token')); } } ``` +### Angular 13 or below +Add the cookie service to your `app.module.ts` as a provider: + +```typescript +import {CookieService} from 'ngx-cookie-service'; + +@NgModule({ + ... + providers:[CookieService], +... +}) + +export class AppModule { +} +``` + +Then, import and inject it into a constructor: + +```typescript +constructor(private cookieService: CookieService) +{ + this.cookieService.set('token', 'Hello World'); + console.log(this.cookieService.get('token')); +} +``` ## Server Side Rendering @@ -150,22 +150,14 @@ server.get('*', (req, res) => { cookies in SSR. Then proceed to use `ngx-cookie-service` as usual. 4. See the [sample repo](https://github.com/pavankjadda/angular-ssr-docker) for more details. -## Demo - -https://stackblitz.com/edit/angular-ivy-1lrgdt?file=src%2Fapp%2Fapp.component.ts - ## Supported Versions - -`ViewEngine` support has been removed on 13.x.x. For Angular versions 13.x.x or later use the latest version of the -library. For versions <=12.x.x, use 12.0.3 version +We follow angular [LTS versions](https://angular.dev/reference/versions#actively-supported-versions). The latest version of the library supports Angular 17.x.x. Angular 14.x.x or below is not supported. | Angular Version | Supported Version | -| ---------------------- | ----------------- | +|------------------------|-------------------| +| 17.x.x | 17.x.x | | 16.x.x | 16.x.x | | 15.x.x | 15.x.x | -| 14.x.x | 14.x.x | -| 13.x.x | 13.x.x | -| <=12.x.x (View Engine) | 12.0.3 | # API