I'm not sure of the small details here, so maybe this isn't even supposed to workâbut it seems like there should be some solution to this. I have a parent component that uses two child components in tabs, like so:
<div class="container" *ngIf="page === 'tab1'">
<refresher-component></refresher-component>
<child-component1></child-component1>
</div>
<div class="container" *ngIf="page === 'tab2'">
<refresher-component></refresher-component>
<child-component2></child-component2>
</div>
The parent also has a refresher component, that is responsible for refreshing the data in both of the tabs. Each of the child components injects a service that implements the Refreshable interface:
- Child component 1:
constructor(private service1: Service1)
- Child component 2:
constructor(private service2: Service2)
Each service looks like this (replace 1 with 2 for 2nd service):
@Injectable()
export class Service1 implements Refreshable<Type1[]>
The refersher-component
looks like this:
public constructor(@Inject(RefresherServiceToken) public refreshableService: Refreshable<any>) {
console.log('refreshable', this.refreshableService);
}
What happens is that when I load the page (1st tab is default), the console.log
outputs Service1. However, when changing to Tab 2, the constructor is called again, but it also outputs Service1. Therefore the refresh is also done on Service1's data, and does not affect Service2.
Is this normal behavior, because the route doesn't change, and do I need to add something to reset the service? Is there a simple way to troubleshoot this behavior in general? (Angular 8)