无法使用反应形式将my-date-picker输入初始化为当前日期

问题描述 投票:0回答:1

我正在使用MyDatePickerModule(https://github.com/kekeh/mydatepicker),并希望将我的日期选择器初始化为当前日期。我正在使用反应形式。

我跟着这个https://github.com/kekeh/mydatepicker/wiki/Initialize-with-selDate-attribute

但它仍然无法正常工作。

这是模板部分:

<my-date-picker
  id="myDate"
  name="myDate"
  [options]="myDatePickerOptions"
  formControlName="myDate">
</my-date-picker>

myComponent.ts:

public todayDateToMyDatePicker(){
let d: Date = new Date();
return {year: d.getFullYear(),
  month: d.getMonth() + 1,
  day: d.getDate()};
 }

在init表单方法中:

this.myForm= this.builder.group({
  myDate: [this.todayDateToMyDatePicker()]
})
angular datepicker reactive-forms
1个回答
0
投票
ngOnInIt() {
  this.updateValue();
}


updateValue() {
this.myForm.patchValue({
      myDate: this.todayDateToMyDatePicker()
    });
}
© www.soinside.com 2019 - 2024. All rights reserved.