3

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

pantonis
  • 5,601
  • 12
  • 58
  • 115
  • Is it surrounded with ? Maybe you could insert more of your code. – nyluje Nov 28 '16 at 22:15
  • this looks correct to me. I use displayFormat as "D MMMM YYYY" in my case, but I guess "DD" is in the specs (maybe double check that). How does it look if you take all the part outside , and place it just beneath
    ? Are you sure this.data.DateAvailable is the right format is expecting likely a date formatted as it should display it (MMM DD YYYY)?
    – nyluje Nov 29 '16 at 09:04
  • In the class linked to the html template, did you set that form1 (a FormGroup object) includes dateAvailableFormControl. Maybe this part of your code should be added too. – nyluje Nov 29 '16 at 09:09
  • Check this post for more details: https://stackoverflow.com/a/47843362/7829826 – Daniel Delgado Dec 16 '17 at 07:05

1 Answers1

2

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.

pantonis
  • 5,601
  • 12
  • 58
  • 115