【问题标题】:Call method when input text is changed输入文本改变时的调用方法
【发布时间】:2018-09-11 23:55:59
【问题描述】:

我正在使用带有 Materialize 的 Angular 5,并且我有一个完美运行的日期选择器:

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

我想在输入日期更改时调用类似“dateChanged(date)”的方法,例如,我尝试过使用 (change)="dateChanged($event)",但不起作用。

【问题讨论】:

    标签: angular typescript angular5 angular2-forms materialize


    【解决方案1】:

    我也不是角度专家,我正在学习。 如果你使用 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! 我建议使用反应形式! 你能试着告诉我它是否有效吗? 感谢和抱歉我的知识和英语!

    【讨论】:

    • 恕我直言,这应该是公认的答案。反应式表单是要走的路。
    【解决方案2】:

    使用 ngModelngModelChange

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

    【讨论】:

      猜你喜欢
      • 2018-05-24
      • 2018-08-18
      • 2021-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-04
      • 2017-11-28
      • 1970-01-01
      相关资源
      最近更新 更多