如何使用my-date-picker

时间:2018-06-02 13:00:01

标签: angular datepicker

我正在使用my-date-picker。如何使用默认日期(我从服务获得的默认日期)填充日期字段。我使用以下代码从服务返回outOldestDate。我试图将其设置为onInit函数中的默认日期。但是这个日期还没有填充。

 <my-date-picker name="outOldestDate" class="form-control required" placeholder="Oldest" [options]="myDatePickerOptions formControlName="outOldestDate"></my-date-picker>

public myDatePickerOptions: IMyDpOptions = {
    // other options...
    dateFormat: 'yyyy-mm-dd'
};


    ngOnInit() {
        this.accountReceivableForm = this.formBuilder.group({
          outOldestDate: [null, Validators.required]
        });
this.getDate();
}


getDate(): void {
//service call happens here
 resultArray => {
        this.ng4LoadingSpinnerService.hide();
        console.log(resultArray);
        this.ARHospitalListData = resultArray;
        this.outOldestDate = this.ARHospitalListData.dischargeDate.fromDate;

}

}

1 个答案:

答案 0 :(得分:1)

 this.outOldestDate = { formatted: this.ARHospitalListData.dischargeDate.fromDate };

添加格式化解决了问题