【发布时间】:2018-02-05 15:51:13
【问题描述】:
我有两个带有 ngx-bootstrap 的选项卡,如下所示,我想以编程方式停止选项卡功能的工作:
<tabset>
<tab heading="First">Tab 1 content</tab>
<tab heading="Second">Tab 2 content</tab>
</tabset>
<label>Edit in progress: </label>
<input type="checkbox" [(ngModel)]="isTabSwitchEnabled">
基本上,如果我在 Tab 1 中有一个脏表格,我想弹出一个“放弃更改?”允许用户“导航”到 Tab 2 之前的对话框。我在 ngx-bootstrap tabs API 上看不到我可以使用的任何东西。
我有一个示例Stackblitz,我尝试在标签上使用[disabled],它可以部分工作,但不能完全工作,因为我无法以编程方式将标签设置为活动状态(或者我不知道如何):
export class MyComponent {
disableSwitching: boolean;
@ViewChild('tabset') tabset: TabsetComponent;
@ViewChild('first') first: TabDirective;
@ViewChild('second') second: TabDirective;
confirmTabSwitch($event) {
if (this.disableSwitching) {
const confirm = window.confirm('Discard changes and switch tab?');
if (confirm) {
this.disableSwitching = false;
this.second.active = true;
}
}
}
}
this.second.active = true 不会切换到新标签,只会将其标记为活动状态。如果我尝试使用 this.tabset.tabs[index].active = true; 也是一样。
有没有办法拥有这个功能?启用和禁用切换标签?理想情况下也将它绑定到路由器(但我肯定需要编程访问)。
【问题讨论】:
标签: angular twitter-bootstrap tabs ngx-bootstrap