Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 ion-datetime form binding

I have the following:

<ion-header>
    <ion-navbar>
        <button ion-button menuToggle>
            <ion-icon name="menu"></ion-icon>
        </button>
        <ion-title>Add new</ion-title>
    </ion-navbar>
</ion-header>

<ion-content class="ion-backdrop" padding>
    <form [formGroup]="form1" class="form" (ngSubmit)="onSubmit(form1.value)">
        <ion-card>
            <ion-list>
                <ion-item>
                    <ion-label>Available:</ion-label>
                    <ion-datetime displayFormat="MMM DD YYYY" formControlName="dateAvailableFormControl">
                    </ion-datetime>
                </ion-item>
            </ion-list>
        </ion-card>     
    </form>
</ion-content>

and my ts code is:

this.dateAvailableFormControl.setValue(this.data.DateAvailable);

where this.data.DateAvailable is Date type.

I cannot see anything when page loads. All other bindings work fine except from the ion-datetime.

Does anyone knows why this happens?

Thanks in advance

like image 881
pantonis Avatar asked Sep 20 '26 18:09

pantonis


1 Answers

I think I found what was the problem. Dont know if this is a bug of ionic 2 or is how it works with ng2.

My Date value was

2016-11-29T09:15:48.8579573Z

as soon as I change it to:

2016-11-29T09:15:48.857Z

it worked.

like image 171
pantonis Avatar answered Sep 22 '26 21:09

pantonis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!