Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 datetime component doesn't trigger change event when setting default value

I m using Ionic datetime component in my ionic app

    <ion-datetime 
        displayFormat="YYYY/MM/DD" 
        pickerFormat="YYYY MMMM DD" [(ngModel)]="summaryDate" 
       (ionChange)="getDashboardItemsByDate()">
   </ion-datetime>

and in .ts file I set default date to current date like this

 public summaryDate: any = new Date().toISOString();

This works perfectly fine, but however the problem I have is, it invokes ionChange event at the beginning (as I have set default value for this component). I just want to trigger this event when user selects the date not at the beginning when I set its default value. Any help?

like image 611
WatsMyName Avatar asked Jul 03 '17 04:07

WatsMyName


2 Answers

This should work fine

(ionChange)="changed($event)"

notice ($event)

like image 133
Omkar Frozen Avatar answered Nov 06 '22 21:11

Omkar Frozen


Use (ngModelChange) of angular instead of (ionChange)

It's a bug from ionic. https://github.com/ionic-team/ionic/issues/7806 Try updating ionic to the last version, maybe it's fixed. But the angular way will work just fine.

like image 22
Sebastian Giro Avatar answered Nov 06 '22 23:11

Sebastian Giro