question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v4: ion-datetime not working, ngModel/ionChange/ngModelChange not working as well!

See original GitHub issue

Ionic version: (check one with “x”) (For Ionic 1.x issues, please use https://github.com/ionic-team/ionic-v1) [ ] 2.x [ ] 3.x [x] 4.x

I’m submitting a … (check one with “x”) [x] bug report [ ] feature request

Current behavior:

ion-datetime doesn’t work in v4, unable to bind via ngModel, ionChange and ngModelChange doesn’t trigger any events.

Expected behavior:

Steps to reproduce:

Related code:

<ion-item>
   <ion-label position="stacked">Event Time</ion-label>
   <ion-datetime displayFormat="h:mm A" [(ngModel)]="eventTime" (ngModelChange)="save()" (ionChange)="timeChanged($event)" pickerFormat="h mm A"></ion-datetime>
</ion-item>
<ion-button (click)="save()" expand="block" fill="outline">Save</ion-button>


export class HomePage implements DoCheck {
  eventTime: any;

  save() {
    console.log(this.eventTime);   //undefined
  }

  timeChanged(event: any) {
    console.log(event);                 //undefined
  }

  ngDoCheck() {
    console.log(this.eventTime);
  }
}

Other information:

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

ionic (Ionic CLI)          : 4.0.0-rc.9 (C:\Users\albertc\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework            : @ionic/angular 4.0.0-alpha.7
@angular-devkit/core       : 0.7.0-rc.0
@angular-devkit/schematics : 0.7.0-rc.0
@angular/cli               : 6.0.8
@ionic/ng-toolkit          : 1.0.0-rc.9
@ionic/schematics-angular  : 1.0.0-rc.9

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ngrealishcommented, Sep 4, 2018

had to write in a simple converter using the pickerOptions and moment.js to get my date needed.

    this.dateTimeOptions = {
        buttons: [{
            text: 'Cancel',
        },{
            text: 'Done',
            handler: (dateModel) => {
                const dateTime = moment(dateModel.month.text + " " + dateModel.day.text + "," + dateModel.year.text).toISOString(true);
                this.eventModel.data.timestamp = dateTime;
            }
        }]
    };
    <ion-datetime
        display-format="MMM DD, YYYY"
        picker-format="MMM DD YYYY"
        min="2010"
        max="2030"
        class="form__group__item--input has-value"
        formControlName="date"
        placeholder="Select Date"
        [(ngModel)]="eventModel.data.timestamp"
        [pickerOptions]="dateTimeOptions"
    ></ion-datetime>

YMMV: I only used a date picker selecting month, day and year. If you are selecting times as well, you’ll need to include that properly inside of moment with the returned dateModel

It’s inconvenient and not exactly clean, but it works…

0reactions
kensodemanncommented, Oct 3, 2018

I am unable to duplicate this issue at all using beta.12. This included testing the ionChange event and using formControlName as such.

If this problem persists for you, please open a new issue with a link to a repo containing a sample application that duplicates the issue.

Thank you for using Ionic!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting Date in Ionic Datepicker - Only Days changed and not ...
Setting Date in Ionic Datepicker - Only Days changed and not the Month - Using (ngModelChange) ... I have two date input, Start...
Read more >
Ion-datetime: ngModelChange - ionic-v3
Any ideas on how to properly handle the date change in ion-datetime ? I resolved it by changing (ngModelChange) to (ionChange) .
Read more >
Date picker popup in Ionic 6 | Damir's Corner
Now I have another problem in that when user clicks the Month/Year selection ( top left) the month/year picker wheel correctly appears but...
Read more >
Release notes and release history for Mobiscroll
What's New. Bugfix release. This version fixes several bugs and performance issues for the timeline, scheduler, event calendar, agenda and date picker. It...
Read more >
Ionic 6 ion-datetime | Complete guide - YouTube
Hello Friends, Welcome Back to @CodingTechnyks. In this video, we are going to work with Ionic 6 ion - datetime using​ #ionic #angular...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found