DateTime - default to todays date

@sdrew @JarrodKoch this is probably a hack but you can set the default value of the picker with:

this.dateTime.setValue(new Date().toISOString());

Where dateTime is the reference to the ion-datetime via:

@ViewChild('dateTime') dateTime;

Here is a full example:

export class MyDateForm {
  @ViewChild('dateTime') dateTime;

  form: FormGroup
  myDate: FormControl = new FormControl('', Validators.required)

  constructor(private fb: FormBuilder) {}

  ngOnInit() {
    this.form = this.fb.group({
      myDate: this.myDate
    });

    setTimeout(_ => {
      this.dateTime.setValue(new Date().toISOString());
    });
  }
}

with the template:

  <ion-datetime
    #dateTime
    displayFormat="MMM DD, YYYY HH:mm"
    formControlName="myDate"></ion-datetime>
5 Likes