I want to get which tab is active. I tried to use a @ViewChild
decorator and accessing the element properties that way, but it returns null
.
"@angular/material": "^6.2.1". The way to get selected tab index on-load (after template has loaded) and when the tab is focused.
my.component.ts
export class MyComponent implements OnInit, AfterViewInit {
@ViewChild('tabGroup') tabGroup;
ngAfterViewInit() {
console.log(this.tabGroup.selectedIndex);
}
public tabChanged(tabChangeEvent: MatTabChangeEvent): void {
console.log(tabChangeEvent);
}
}
my.component.html
Tab 1
Tab Content
Tab 2
Tab Content