我正在尝试创建一个包装器,该包装器MatTabs
公开了所有属性,MatTabs
并且遇到了这个问题:
Angular Material Tabs not working with wrapper component。我向它添加了其他选项卡属性和事件。这些事件似乎正在正确触发。
当我添加一个新选项卡时出现问题。数组正在更新,但 UI 保持不变。
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);
}
理想情况下,我希望公开MatTabs
提供开箱即用的所有功能,然后再公开一些。