There are two instances of custom-component
spawned by a shared parent with distinct data, each displayed as a tab in the mat-tab-group
.
<mat-tab-group>
<mat-tab label="TAB1">
<ng-template matTabContent>
<custom-component [data]="tab1data"></custom-component>
</ng-template>
</mat-tab>
<mat-tab label="TAB2">
<ng-template matTabContent>
<custom-component [data]="tab2data"></custom-component>
</ng-template>
</mat-tab>
</mat-tab-group>
The data
attribute is utilized to set the internal _data
which is then enclosed within MatTableDataSource
:
@Input()
set data(val: Data[]) {
this._data = val;
this.loadData();
}
loadData(): void {
this.dataSource = new MatTableDataSource<Data>(this._data);
this.dataSource.sort = this.sort;
}
In certain scenarios, actions performed on the component within the first tab must impact the data displayed in the second tab.
Is there a method to share references between components so that I can modify _data
and initiate loadData()
from another component?