Answer the question
In order to leave comments, you need to log in
Why is the data not updated in the service?
I have a module with a factory defined:
providers: [
CustomBlockService,
{
provide: DocumentCustomBlock,
useFactory: (httpClient: HttpClient, customBlockService: CustomBlockService) => {
switch (customBlockService.block.type) {
case 'doc_num_date_block':
return new DocNumDateBlock(
httpClient,
customBlockService,
new DocNumDateBlockFormGroup(createFormControls(customBlockService.value)),
);
case 'find_unom_by_address_block':
return new FindUnomAddressBlock(
httpClient,
customBlockService,
new FindUnomAddressBlockFormGroup(createFormControls(customBlockService.value)),
);
default:
throw 'Error type custom block!';
}
},
deps: [HttpClient, CustomBlockService],
},
],
public setDocument(): void {
this.customBlockService.block = this.block;
}
this.customBlockService.block = this.block;
in provider D ocumentCustomBlock
. this.customBlockService.block = this.block;
one, I see the old data in the service. Answer the question
In order to leave comments, you need to log in
The factory is created once when the dependency injection mechanisms are called .
What you are trying to implement is called a factory provider .
You correctly understood the reason - the result of the execution is cached due to the fact that the instantiated service is cached.
You need to remove block instantiation inside the service.
Something like that:
providers: [
CustomBlockService,
{
provide: DocumentCustomBlock,
useFactory: (httpClient: HttpClient, customBlockService: CustomBlockService) => {
return new ControlBlock(httpClient, customBlockService.block.type);
},
deps: [HttpClient, CustomBlockService],
},
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question