输入文本改变时的调用方法

Call method when input text is changed

我将 Angular 5 与 Materialise 一起使用,我有一个完美运行的日期选择器:

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

我想在更改此输入日期时调用类似 "dateChanged(date)" 的方法,例如,我尝试使用 (change)="dateChanged($event)",但没有用。

使用 ngModelngModelChange

<input materialize="pickadate"  [ngModel]="date"
 (ngModelChange)="onKey($event)" type="text" class="datepicker" placeholder="Selecione a Data" [materializeParams]=datePickerParams>

我也不是angular专家,我正在学习。 如果你使用 Reactive Form,你可以使用类似

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()
})

您只需要在日期输入中设置formControlName即可! 我建议使用反应形式! 你能试试告诉我它是否有效吗? 谢谢,对不起我的知识和英语!