File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -391,6 +391,14 @@ class HttpResourceImpl<T>
391391 this . client = injector . get ( HttpClient ) ;
392392 }
393393
394+ override set ( value : T ) : void {
395+ super . set ( value ) ;
396+
397+ this . _headers . set ( undefined ) ;
398+ this . _progress . set ( undefined ) ;
399+ this . _statusCode . set ( undefined ) ;
400+ }
401+
394402 // This is a type only override of the method
395403 declare hasValue : ( ) => this is HttpResourceRef < Exclude < T , undefined > > ;
396404}
Original file line number Diff line number Diff line change @@ -319,4 +319,19 @@ describe('httpResource', () => {
319319 req = backend . expectOne ( '/data' ) ;
320320 req . flush ( [ ] ) ;
321321 } ) ;
322+
323+ it ( 'should reset past request data when using set()' , async ( ) => {
324+ const backend = TestBed . inject ( HttpTestingController ) ;
325+ const res = httpResource ( ( ) => '/data' , { injector : TestBed . inject ( Injector ) } ) ;
326+ TestBed . tick ( ) ;
327+ const req = backend . expectOne ( '/data' ) ;
328+ req . flush ( [ ] ) ;
329+ await TestBed . inject ( ApplicationRef ) . whenStable ( ) ;
330+
331+ res . set ( [ ] ) ;
332+
333+ expect ( res . headers ( ) ) . toBe ( undefined ) ;
334+ expect ( res . progress ( ) ) . toBe ( undefined ) ;
335+ expect ( res . statusCode ( ) ) . toBe ( undefined ) ;
336+ } ) ;
322337} ) ;
You can’t perform that action at this time.
0 commit comments