V. Pivet
V. Pivet

Reputation: 1328

Ionic 2 : Set date-time value to null

I try to use Date Picker with ionic and I don't know how to clear value in the input.

I want to add a value in the list to represent a "null" value : something like this :

enter image description here

There is my code :

<ion-item>
      <ion-label>Année</ion-label>
      <ion-datetime [(ngModel)]="year" doneText="Valider" cancelText="Annuler" displayFormat="YYYY"></ion-datetime>
    </ion-item>

Upvotes: 2

Views: 2506

Answers (1)

Swapnil Patwa
Swapnil Patwa

Reputation: 4099

You can clear the value on click of cancel button (cancelText) instead.

HTML:

<ion-item>
      <ion-label>Année</ion-label>
      <ion-datetime [(ngModel)]="year" (ionCancel)="clear()" doneText="Valider" cancelText="Annuler" displayFormat="YYYY"></ion-datetime>
</ion-item>

TS:

clear() {
    this.year = null;
}

Upvotes: 4

Related Questions