我试图将PrimeNg TabView组件与confirmDialog一起使用,但没有成功,下面是我的代码:
<p-tabView (onChange)="onTabChange($event)" [(activeIndex)]="index">...</p-tabView>
onTabChange(event){
this.confirmationService.confirm({
message: 'Do you confirm ?',
accept: () => {
this.index = event.index;
},
reject:() =>{ }
});
}您对如何防止或允许使用“确认”对话框更改选项卡有想法吗?
谢谢
发布于 2019-01-30 09:28:19
基于材料设计选项卡的类似solution,下面是解决我的问题的方法:
<p-tabView #onglets>...</p-tabView>@ViewChild('onglets') onglets: TabView; this.onglets.open = this.interceptOngletChange.bind(this); ... interceptOngletChange(event: Event, tab: TabPanel){ const result = confirm(你真的想离开这个标签吗?); return result && TabView.prototype.open.apply(this.onglets, argumentsList); }); }发布于 2022-02-24 10:51:19
我也有类似的问题。在选项卡更改之前需要显示对话框。
我的解决方案:
HTML
<p-tabView #tabView (onChange)="onChange($event)" />TS
@ViewChild('tabView') tabView: TabView;
onChange(event: any) {
const previoustab = this.tabView.tabs[this.prevIndex]; //saved previous/initial index
previoustab.selected = true;
const selectedTab = this.tabView.tabs[event.index];
selectedTab.selected = false;
this.tabView.activeIndex = this.prevIndex;
this.nextIndex= event.index;
}
GoToNextTab() {
this.tabView.activeIndex = this.nextIndex;
this.prevIndex= this.nextIndex;
this.tabView.open(undefined, this.tabView.tabs[this.nextIndex]);
}使用此代码,您将保留在所选选项卡上,而不会更改选项卡样式。
https://stackoverflow.com/questions/54418932
复制相似问题