javascript - Ionic 2 Popover 关闭

标签 javascript angular typescript ionic2 ionic3

我有一个弹出窗口,它将我带到另一个页面,在那里我弹出回到根页面 (popToRoot),在事件上重新加载数据/dom,然后当 json 数据从返回时关闭 promise 中的弹出窗口服务器。如果我在解雇时超时很长,一切都会正常。

  dismissPopup() {
    if (this.popover) {
      let that = this;
      setTimeout(function () {
        that.popover.dismiss();
      }, 500);
    }
  }

如果我将超时设置得太低,比如 100 毫秒,它不会关闭,因为 dom 仍在加载。

但是,我认为超时可能不是最佳做法。如果有人的设计速度很慢,而且时间不够怎么办?

有人可以提出任何建议吗?我应该检测 dom 何时加载,然后调用 dismiss 吗?如何检查 dom 是否已加载?

谢谢

最佳答案

您可以使用 Events 而不是使用超时.通过这样做,您可以发布并在数据从服务器返回(并且一切就绪)时发生事件,并订阅该事件以了解何时需要关闭弹出窗口。

import { Events } from 'ionic-angular';

constructor(public events: Events) {}

// first page (publish an event when data is ready)
events.publish('loading:finished', data);

// second page (listen for the loading finished event)
events.subscribe('loading:finished', (eventData) => {
  // eventData is an array of parameters, so grab our first and only arg
  console.log('Data:', eventData[0]);
});

关于javascript - Ionic 2 Popover 关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39174327/

相关文章:

javascript - 使用axios时catch block 中的状态码300返回错误

tomcat - 如何在 tomcat 服务器(Windows Server 2012)上部署 Angular 2 应用程序

javascript - 如何更改事件上的按钮颜色?

javascript - 添加新参数后发生错误

javascript - backbone.js 在脚本中找不到错误

javascript - 停止页面滚动到指定的 Div(或页脚元素)

Javascript uint32 数学不起作用?

javascript - 如何更新使用 ReactDOM.render() 渲染的 React Component 的 props

javascript - 使用指令将组件动态添加到子元素

reactjs - 在 typescript 中启用react-hooks eslint插件。 tslint 中没有插件