2

PopoverController 在 Ionic 4 中是如何工作的?

当前文档不正确并且没有重大更改?

const popover = this.popoverCtrl.create({
  component: 'PopupMenuComponent',
  ev: event
});

popover.present();

我创建了一个组件,当我尝试展示它时,我收到以下错误...

[ts] Property 'present' does not exist on type 'Promise<HTMLIonPopoverElement>'. Did you forget to use 'await'?

谢谢。

4

1 回答 1

3

在您的示例中,您没有等待它。从 Alpha-7 开始,该create方法返回一个承诺。您可以在此处找到最新的文档。看看这个例子:

import { Component } from '@angular/core';
import { PopoverController } from '@ionic/angular';

@Component({
    template: `
        <ion-list no-margin>
            <ion-item (click)="onDismiss()">Dismiss</ion-item>
        </ion-list>
    `
})
export class PopupMenuComponentPopover {
    constructor(private popoverCtrl: PopoverController) {

    }

    async onDismiss() {
        try {
            await this.popoverCtrl.dismiss();
        } catch (e) {
            //click more than one time popover throws error, so ignore...
        }

    }
}

以下是如何打开它:

  async openPopover(args) {
    const popover = await this.popoverController.create({
      component: PopupMenuComponentPopover,
      ev: args,
      translucent: false
    });
    return await popover.present();
  }

编辑:你可以这样称呼它:

@NgModule({
  ...
  declarations: [DashboardWebsiteMorePopover],
  entryComponents: [DashboardWebsiteMorePopover],
  ...
})
export class PopupMenuComponentModule {}
于 2018-06-17T17:55:32.447 回答