I have a parent component that loads child components conditionally. One of them being:
<ng-container *ngIf="someCondition">
<app-some-child></app-some-child>
</ng-container>
There are no child routes for the parent component. The route has a resolver to which app-some-child
subscribes to:
this._activatedRoute.data.subscribe(({ clientData }) => {
// Client data came from a server
});
The child component app-some-child
is used to create the client data:
this.clientService.create(client).subscribe(res => {
// Client created
});
The problem
When I navigate back and forth between child components, the resolver is obviously "not designed" to be called again in this way. So, after creating a client, what is the best approach to use in order to keep the client data when initializing app-some-child
again but still using the resolver?
"Dirty" solutions:
- I could re-subscribe to getting the client from server on
app-child-component
but then I'm dealing with duplicate subscriptions. - I can use a singleton to keep the client in memory after creating it and subscribe to it.