I have a module of dialog that has a factory defined:
@NgModule({
declarations: [...components, ...directives],
imports: [...modules],
providers: [
CustomBlockService,
{
provide: DocumentCustomBlock,
useFactory: (httpClient: HttpClient, customBlockService: CustomBlockService) => {
console.log(customBlockService.type);
switch (customBlockService.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],
},
],
entryComponents: [...components],
})
export class DialogLoadDocumentModule {}
This module of the dialog box jerks from the parent component, before the window opens, the selected block is added to the CustomBlockService service:
public setDocument(): void {
this.customBlockService.block = this.block;
}
The first time it works, in the dialog I see the selected data this.customBlockService.block = this.block;
in the DocumentCustomBlock
provider.
When the window is closed and reopened with a new this.customBlockService.block = this.block;
then I see old data in the service.
So, If to do the console:
useFactory: (httpClient: HttpClient, customBlockService: CustomBlockService) => {
console.log(customBlockService.type);
});
I noted that console works only first time, then does not, despite property in CustomBlockService
was chnaged.
I have tried to add this:
{ provide: CustomBlockService, useClass: CustomBlockService },
in the same module to create a new instance CustomBlockService
every time when modules is loaded. But there is not success.