以反应形式将值分配给日期选择器

时间:2020-03-30 14:26:30

标签: angular datepicker angular-reactive-forms

我的项目中有一个反应形式,其中两个输入是日期输入,带有一个datepicker,但是当我尝试为它们分配一个值时,会出现一个错误TypeError: date.match is not a function

form.ts

ngOnInit() {
    this.id = this.route.snapshot.url[1].path
    this.dataService.getProject(this.id).subscribe((rps) => {
        this.agreementSumary = {
            agreementType: rps.agreement.agreementType,
            referenceNumber: rps.agreement.referenceNumber,
            isEffective: rps.agreement.isEffective,
            dateEffective: rps.agreement.dateEffective,
            dateExpiration: rps.agreement.dateExpiration
        }
        this.agreementEditFrm.controls["dateEffective"].setValue( new Date(this.agreementSumary["dateEffective"]))
        this.agreementEditFrm.controls["dateExpiration"].setValue( new Date(this.agreementSumary["dateExpiration"]))
    },
        error => console.log(error)
    )
}

我从服务中获得的值是字符串,我正在解析它们,因为表单中的输入是datepicker

0 个答案:

没有答案