How to set value of ion-datetime manually?


#1

I am building a edit profile form, I am setting all the items to the defined user specific values but am confused how to set value of ion-datetime element? Please help.

HTML:

<ion-list>

    <ion-item>
      <ion-label floating>Name</ion-label>
      <ion-input type="text" [(ngModel)]="userInfo.Name"></ion-input>
    </ion-item>

    <ion-item>
      <ion-label floating>Sex</ion-label>
      <ion-input type="text" [(ngModel)]="userInfo.Sex"></ion-input>
    </ion-item>

    <ion-item>
      <ion-label>D.O.B.</ion-label>
      <ion-datetime displayFormat="DD/MM/YYYY" [(ngModel)]="userInfo.DOB"></ion-datetime>
    </ion-item>

    <ion-item>
      <ion-label>T.O.B.</ion-label>
      <ion-datetime displayFormat="HH:mm" [(ngModel)]="userInfo.TOB"></ion-datetime>
    </ion-item>

    <ion-item>
      <ion-label>P.O.B.</ion-label>
      <ion-datetime type="text" [(ngModel)]="userInfo.POB"></ion-datetime>
    </ion-item>

    <ion-item>
      <ion-label>email</ion-label>
      <ion-input type="email" [(ngModel)]="userInfo.Email"></ion-input>
    </ion-item>

    <ion-item>
      <ion-label>City of Residence</ion-label>
      <ion-input type="text" [(ngModel)]="userInfo.City"></ion-input>
    </ion-item>

  </ion-list>

Thanks and Regards!


#2

Same way you do any other form control. Set userInfo.DOB to an ISO8601 string.


#3

but it then takes wrong values, i don’t understand how.