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

4
  • Is it surrounded with <ion-item>? Maybe you could insert more of your code. Commented Nov 28, 2016 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 <ion-item> part outside <ion-card>, and place it just beneath <form>? Are you sure this.data.DateAvailable is the right format is expecting likely a date formatted as it should display it (MMM DD YYYY)? Commented Nov 29, 2016 at 9: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. Commented Nov 29, 2016 at 9:09
  • Check this post for more details: stackoverflow.com/a/47843362/7829826 Commented Dec 16, 2017 at 7:05

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.