Change event not working on ion-datetime after ionic2 Beta 8

#1

Hi All

Change event is not working in the following code. Earlier it was working in beta 7. Please help

ion-datetime displayFormat=“YYYY-MM-DD” (change)=“changeDate(birthDate)” [(ngModel)]=“birthDate”

#2

see the changelog

#3

It worked. thanks a lot :slight_smile:

#4

just a question here… I see this in many places but never understand why? Why do you pass your “birthDate” as parameter in your function changeDate if you define as 2way binding on your element with [(ngModel)]=“birthDate”?

You would get the value inside your function even if you don’t pass it as a parameter.

changeDate(birthDate) {
 // this.birthDate and birthDate should be the same value?
}
#5

Hi manuvaldes, the link is crashed, do you tell me the solution?
Thank you

#6

Hi @skoff I think it’s good design, becuase:

  1. it does not tie your function to the global scope of the class (e.g.: this.birthDate)
    1. this would make it easier to refactor this method later if need be
    2. This also makes it more re-usable
  2. It is easier to test in isolation
1 Like
#7

For anyone else coming here through google and getting a 404 on the solution link above… The solution is to use (ionChange) instead of (change)

19 Likes
#8

hi, how to clear ion-datetime after choosing a date… there are only 2 buttons , done and cancel…but none of them clears the input !!!

#9

I hijacked the Cancel button to do this - I changed the text to “Clear” and used (ionCancel)=“clearTimeFilter()”. If they want to Cancel then they can click somewhere else on the screen

1 Like
#11

Hey, great there!..
thanks