T
T
tyoma_koder2021-09-14 14:33:34
Angular
tyoma_koder, 2021-09-14 14:33:34

Why is ngmodel not working?

I work in ionic
There is an input for entering a date with a two-way binding

<ion-datetime (ionChange)="validateBookingDate()"
                      [(ngModel)]="bookingDate"
                      displayFormat="DD MMMM YYYY"
                      pickerFormat="DD MMMM YYYY" ></ion-datetime>
      </ion-item>

When the date is entered, this function is triggered, which checks the correctness of the entered value, if it is incorrect, then the input value is replaced with an empty string
validateBookingDate(){
    if(this.product.booking.includes(this.bookingDate)){
      this.bookingDate = ""
      alert('товар уже забронирован на эту дату')
    }
  }

The problem is that if you immediately select the wrong date, then the variable is assigned an empty string, but the wrong date is displayed in the input, but if you first select the correct one and then the wrong one, then everything works as it should

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sleeper_king_of_bones, 2021-10-15
@Sleeper_king_of_bones

Try passing null.this.bookingDate = null;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question