【发布时间】:2020-06-30 13:49:34
【问题描述】:
我想根据子组件中的按钮单击来切换选项卡。我该怎么做呢
parent component
<mat-tab-group #mytab>
<mat-tab label="First">
Content 1
<br>
<br>
<br>
<button (click)="next()">Next</button>
</mat-tab>
<mat-tab label="Second">
<app-tab-child></app-tab-child>
</mat-tab>
<mat-tab label="Third"> Content 3 </mat-tab>
</mat-tab-group>
export class TabGroupBasicExample {
@ViewChild("mytab", { static: true }) tab: any;
next() {
this.tab.selectedIndex = 1;
}
}
Child Component
<p>
tab-child !
</p>
<br>
<br>
<br>
<button (click)="next()">Next</button>
如何根据子组件中的下一个按钮单击来切换选项卡?
【问题讨论】: