首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PrimeNg TabView和ConfirmDialog

PrimeNg TabView和ConfirmDialog
EN

Stack Overflow用户
提问于 2019-01-29 10:28:27
回答 2查看 1.5K关注 0票数 1

我试图将PrimeNg TabView组件与confirmDialog一起使用,但没有成功,下面是我的代码:

代码语言:javascript
复制
<p-tabView (onChange)="onTabChange($event)" [(activeIndex)]="index">...</p-tabView> 


  onTabChange(event){
    this.confirmationService.confirm({
      message: 'Do you confirm ?',
      accept:  () => {
      this.index = event.index;
      },
      reject:() =>{        }
      });
   }

您对如何防止或允许使用“确认”对话框更改选项卡有想法吗?

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-01-30 09:28:19

基于材料设计选项卡的类似solution,下面是解决我的问题的方法:

  1. html中,声明引用TabView DOM对象的局部变量: <p-tabView #onglets>...</p-tabView>
  2. component.ts中,更改在单击带有特定函数的选项卡以匹配您的情况时调用的默认函数: @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); }); }
票数 4
EN

Stack Overflow用户

发布于 2022-02-24 10:51:19

我也有类似的问题。在选项卡更改之前需要显示对话框。

我的解决方案:

HTML

代码语言:javascript
复制
<p-tabView #tabView (onChange)="onChange($event)" />

TS

代码语言:javascript
复制
@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]);
  }

使用此代码,您将保留在所选选项卡上,而不会更改选项卡样式。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54418932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档