本文介绍了如何在不单击“取消"按钮的情况下关闭Ionic2 Datetime弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ionic 2项目中,我需要在特定的空闲超时后使用户注销.这样做时,我注意到在调用注销事件并重定向到登录页面之前,无法关闭Datetime弹出窗口.在重定向到登录页面之前,我需要关闭该弹出窗口.下面是我正在处理的代码示例

In an Ionic 2 project, I need make the user logout after a certain idle timeout. While doing so, I noticed that I cannot close the Datetime popup is before invoking the logout event and redirecting to the login page.I need to close that popup before redirecting to the login page.Below is the code sample I an working on

<ion-datetime (ionCancel)="onCancelDateTime()" [(ngModel)]="dateTime">

</ion-datetime>

关闭弹出窗口时会触发(ionCancel)事件.

The (ionCancel) event is fired when close the popup.

有没有办法以编程方式调用此事件的触发?

Is there a way to invoke the firing of this event programmatically?

还是有另一种方法来关闭此Datetime弹出窗口?

Or is there another way to close this Datetime popup?

推荐答案

当前尚无官方记录的Ionic 3以编程方式关闭日期时间选择器的方法.

Currently there is no official documented Ionic 3 way to close the datetime picker programmatically.

但是,我们可以使用Javascript的"dispatchEvent"方法来触发对日期时间"选择器的取消"按钮的点击.

However we can use Javascript 'dispatchEvent' method to trigger a click on the 'Cancel' button of Datetime picker.

这是操作方法:

// Get the reference to the clear button of Datetime picker.
var pickerClearButton = document.getElementsByClassName("picker-button")[0];

// Create a click event to be triggered
var clickEvent = new MouseEvent("click", {
    "view": window,
    "bubbles": true,
    "cancelable": false
});

// Trigger the event
pickerClearButton.dispatchEvent(clickEvent);

我相信这会做的!!

这篇关于如何在不单击“取消"按钮的情况下关闭Ionic2 Datetime弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 06:12
查看更多