问题
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