I am making use of (selectedChange)="functionName($event)"
to get index of my active tab. However on page load i cannot triggger this event as it only gets triggered after i change the tab atleast once to get a returned object of MatTabChangeEvent
containing two objects tab
and index
.
In both tabs i have a mat table with pagination. Also there is a search bar that search data from database and show it in their respective tabs but here the problem for me is if on page load user went straight for search bar then i would not know which tab is currently active so my conditional statement that shows data in their respective tab based on user search will give an Uncaught error
at this.activeTab.index
does not exist. But once the user have actually change the tab then i have the active tab index value and my code keeps working fine.
So how can i get MatTabChangeObject on page load too?
NOTE: I cannot use MatGroup
with ViewChild
since it does not return me MatTabChangeEvent
like object
Here is my code
if(this.tabEvent.index === 0) {
$event.map((a: string) => {
this._printService.getParcelById(this.vId, a, true).subscribe(res => {
data.push(res);
this.child.dataLength = $event.length;
}, err => {
data = [];
this._sb.open({
message : 'Either the parcel id does not exist in the system or it is incorrect',
type: 'error'
})
});
});
this.dataSource$ = of(data);
}
else if(this.tabEvent.index === 1) {
$event.map((a: string) => {
this._printService.getParcelById(this.vId, a, false).subscribe(res => {
data.push(res);
this.child.dataLength = $event.length;
}, err => {
data = [];
this._sb.open({
message : 'Either the parcel id does not exist in the system or it is incorrect',
type: 'error'
})
});
});
this.dataSource$ = of(data);
}
I am emitting eventChange value in a function and then assigning that value to this.tabEvent
variable that has a type of MatTabChangeEvent