Ion-datetime ngModel binding

Hi to everyone,
my goal is simply an automatic copy of a date value from a ion-datetime to an other ion-datetime.
This is what i’m doing:


        <ion-datetime name="dsi"  [(ngModel)]="dsival" (ionChange)="changedsi($event)"></ion-datetime>
        <ion-datetime name="dsiv"  [(ngModel)]="mygoal"></ion-datetime>


changedsi(data) {
    //this.mygoal= '2016-05-26T09:16:57.528Z'; //this works
    this.mygoal= data; //this doesn't work (i.e. nothing changed)
    //this.mygoal= data.toISOString(); //this gives error
    //this.mygoal= data.toString(); //this gives error

What i’m doing wrong?

Thank you

You are passing the $event object and setting it to mygoal that’s what you are doing wrong, $event is not a date. Rather, you should simply set mygoal to dsival inside the changedsi method in the ts file like this:

this.mygoal = this.dsival;

Thanks. A simple solution.

1 Like