I was trying to prevent tab change of mat-tab
, if the form in currently active tab is dirty.
But I couldn't find a way to intercept the tab change event.
<mat-tab-group>
<mat-tab label="Tab 0" >
// Tab 0 Content
</mat-tab>
<mat-tab label="Tab 1" >
// Tab 1 Content
</mat-tab>
<mat-tab label="Tab 2" >
// Tab 2 Content
</mat-tab>
</mat-tab-group>
Even though there is a selectedTabChange
event, we can't prevent tab change. we can only switch tab programatically after tab change.
I have got a hack to make it possible. Just posting here to help if someone encounters the same.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…