I'm trying to create a wrapper around MatTabs
that exposes all the properties of the MatTabs
and Came across this question :
Angular Material Tabs not working with wrapper component .
I added other tabs properties and events to it.
The events seems to be triggering properly.
The problem comes when I add a new tab.The array is getting updated but the UI remains same.
HTML
<div>
<span class="example-input-label"> Selected tab index: </span>
<mat-form-field>
<input matInput type="number" [formControl]="selected">
</mat-form-field>
</div>
<div>
<button mat-raised-button
class="example-add-tab-button"
(click)="addTab(selectAfterAdding.checked)">
ADD NEW TAB
<br/>
</button>
<mat-checkbox #selectAfterAdding> Select tab after adding </mat-checkbox>
</div>
<custom-tabs [selectedIndex]="selected.value"
(sqSelectedIndexChange)="selected.setValue($event)">
<custom-tab *ngFor="let tab of tabs; let index = index" [label]="tab">
Contents for {{tab}} tab
<button mat-raised-button
class="example-delete-tab-button"
[disabled]="tabs.length === 1"
(click)="removeTab(index)">
Delete Tab
<br/>
</button>
</custom-tab>
</custom-tabs>
TS
tabs = ['First', 'Second', 'Third'];
selected = new FormControl(0);
addTab(selectAfterAdding: boolean) {
this.tabs.push('New');
console.log(this.tabs);
if (selectAfterAdding) {
this.selected.setValue(this.tabs.length - 1);
}
}
removeTab(index: number) {
this.tabs.splice(index, 1);
}
Ideally I'm looking to expose all the features that MatTabs
provides out of the box and then some.