从其组件中消除Ionic 4 Popover

hug*_*nne 8 popover ionic4

我有一个标准的Ionic 4页面(主页),该页面创建一个使用组件(BusinessDetails)和一个按钮的弹出窗口,该按钮重定向到新页面(RequestTurn)。但是,当我单击该按钮时,弹出窗口不会消失,而是呈现在我的RequestTurn页面顶部。我想我需要从组件(BusinessDetails)中手动关闭它,但是我不知道如何从那里访问弹出窗口的实例,因为它是在主页中创建的。有没有办法做到这一点?

home.page.ts

presentModal(business:Business, event: Event) {
this.popoverController.create(({
    component: BusinessDetailsComponent,
    cssClass: "business-popover",
    showBackdrop: true,
    componentProps: {
        business: business
    }
}) as any).then(popover => popover.present()); }
Run Code Online (Sandbox Code Playgroud)

business-detail.component.ts

goToRequestTurn(id: string) {
   //Need to dismiss popver here (?)
   this.router.navigateByUrl(`/request-turn/${id}`); }
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助。

小智 15

添加 private popoverController: PopoverController到组件构造函数

然后编写一个这样的函数,并在您希望消除模态时调用它

 async DismissClick() {
await this.popoverController.dismiss();
  }
Run Code Online (Sandbox Code Playgroud)

  • 您是指“组件构造函数”吗?因为那是我需要从中删除它的地方,但是在我看来,这样做会注入一个新的控制器实例,因此不会删除原来的那个实例。无论如何,我会尝试一下。谢谢。 (2认同)