Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call method when input text is changed

I'm using Angular 5 with Materialize and I have a datepicker who works perfectly:

<input materialize="pickadate" 
 type="text" class="datepicker" placeholder="Selecione a Data" 
 [materializeParams]=datePickerParams>

I want to call a method like "dateChanged(date)" when this input date is changed, I've tried using (change)="dateChanged($event)" for instance, but isn't working.

like image 313
Murilo Góes de Almeida Avatar asked Jan 25 '26 10:01

Murilo Góes de Almeida


2 Answers

use ngModel with ngModelChange

<input materialize="pickadate"  [ngModel]="date"
 (ngModelChange)="onKey($event)" type="text" class="datepicker" placeholder="Selecione a Data" [materializeParams]=datePickerParams>
like image 178
Sajeetharan Avatar answered Jan 27 '26 00:01

Sajeetharan


I am not an angular expert too, I'm learning. If you use Reactive Form, you can use something like

this.form.get('date').valueChanges.subscribe(date => {
  // do what you want
  // Tue Apr 03 2018 00:00:00 GMT-0300 (Hora oficial do Brasil)
  // you can use date.getTime()
})

You just need to set formControlName in date input! I`d recommend to use reactive form! Can you try and tell me if its worked? Thanks and sorry for my knowlegde and english!

like image 28
Chiien Avatar answered Jan 26 '26 22:01

Chiien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!