@@ -42,65 +42,67 @@ Choose the version corresponding to your Angular version:
4242
4343## Usage
4444
45- ### Module Import
45+ ### Provide HTTP client with Interceptors
4646
47- Import the ` DateInterceptorsModule ` in your ` AppModule ` :
47+ Provide the HTTP client with the ` requestBodyDateFormatInterceptor ` and ` responseBodyDateParseInterceptor ` in your ` main.ts ` :
4848
4949``` ts
50- import { NgModule } from ' @angular/core' ;
51- import { BrowserModule } from ' @angular/platform-browser' ;
52- import { AppComponent } from ' ./app.component' ;
53- import { DateInterceptorsModule } from ' @ngx-toolset/date-interceptors' ;
54-
55- @NgModule ({
56- declarations: [AppComponent ],
57- imports: [
58- BrowserModule ,
59- DateInterceptorsModule .forRoot (),
60- ],
61- bootstrap: [AppComponent ],
62- })
63- export class AppModule {}
50+ import { bootstrapApplication } from ' @angular/platform-browser' ;
51+ import { AppComponent } from ' ./app/app.component' ;
52+ import {
53+ requestBodyDateFormatInterceptor ,
54+ responseBodyDateParseInterceptor
55+ } from ' @ngx-toolset/date-interceptors' ;
56+
57+ bootstrapApplication (AppComponent , {
58+ providers: [
59+ provideHttpClient (
60+ withInterceptors ([
61+ requestBodyDateFormatInterceptor ,
62+ responseBodyDateParseInterceptor
63+ ])
64+ )
65+ ]
66+ });
6467```
6568
6669### Provide Injection Tokens
6770
68- Provide ` API_DATE_FORMAT ` , ` API_URL_REGEX ` and ` DATE_STRING_REGEX ` in your ` AppModule ` :
71+ Provide ` API_DATE_FORMAT ` , ` API_URL_REGEX ` and ` DATE_STRING_REGEX ` in your ` main.ts ` :
6972
7073``` ts
71- import { NgModule } from ' @angular/core' ;
72- import { BrowserModule } from ' @angular/platform-browser' ;
73- import { AppComponent } from ' ./app.component' ;
74+ import { bootstrapApplication } from ' @angular/platform-browser' ;
75+ import { AppComponent } from ' ./app/app.component' ;
7476import {
75- DateInterceptorsModule ,
77+ requestBodyDateFormatInterceptor ,
78+ responseBodyDateParseInterceptor ,
7679 API_URL_REGEX ,
7780 DATE_STRING_REGEX ,
7881 API_DATE_FORMAT
7982} from ' @ngx-toolset/date-interceptors' ;
8083
81- @NgModule ({
82- declarations: [AppComponent ],
83- imports: [
84- BrowserModule ,
85- DateInterceptorsModule .forRoot (),
86- ],
84+ bootstrapApplication (AppComponent , {
8785 providers: [
86+ provideHttpClient (
87+ withInterceptors ([
88+ requestBodyDateFormatInterceptor ,
89+ responseBodyDateParseInterceptor
90+ ])
91+ ),
8892 {
8993 provide: API_URL_REGEX ,
9094 useValue: / ^ https:\/\/ test-url. com/
9195 },
9296 {
9397 provide: DATE_STRING_REGEX ,
94- useValue: / ^ \d {4} -\d {2} -\d {2} T\d {2} :\d {2} :\d {2} \. \d {3} Z$ / ,
98+ useValue: / ^ \d {4} -\d {2} -\d {2} T\d {2} :\d {2} :\d {2} \. \d {3} Z$ /
9599 },
96100 {
97101 provide: API_DATE_FORMAT ,
98- useValue: " yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ,
99- },
100- ],
101- bootstrap: [AppComponent ],
102- })
103- export class AppModule {}
102+ useValue: " yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
103+ }
104+ ]
105+ });
104106```
105107
106108> Hint: The list of options to provide ` API_DATE_FORMAT ` value could be found here: [ date-fns documentation] ( https://date-fns.org/v2.29.1/docs/parse ) .
0 commit comments