Automatically open the datetime component from an ion-select modal in Ionic2?

时光怂恿深爱的人放手 提交于 2021-01-28 09:56:33

问题


In Ionic 2 is there a way to automatically open the datetime component after an event like pressing the OK button in an ion-select modal?

So it will go directly from pressing ok to selecting/pulling up a time on the datetime component.

I have yet to find a solution to directly do this.


回答1:


Here we go

on your template:

<ion-datetime #dateTime style="display:none" displayFormat="h:mm A" pickerFormat="h mm A" [(ngModel)]="startTime"></ion-datetime>

<button (click)="openStart()"></button>

and then in your code

first create a reference to the datetime control:

 @ViewChild('dateTime') sTime;

then add your event code:

 openStart()
    {
        this.sTime.open();
    }

Cheers.




回答2:


this is a bit late but here is a complete answer for this

first import viewchild and date time like this

import { ViewChild} from '@angular/core';
import {DateTime } from 'ionic-angular';

then add those properties to your

mydate :any;
@ViewChild(DateTime) datePicker:DateTime;

then add the datetime component to your view

  <ion-item [hidden]="true">
    <ion-label>Date</ion-label>
    <ion-datetime displayFormat="DD/MM/YYYY  h:mm a" [(ngModel)]="mydate"></ion-datetime>
  </ion-item>

you can now call open on your datepicker

  this.datePicker.open();

also console.log(this.mydate); to ckeck your results



来源:https://stackoverflow.com/questions/38253102/automatically-open-the-datetime-component-from-an-ion-select-modal-in-ionic2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!