patchValue and date-picker

1 Answer 1023 Views
DatePicker Forms
ixen
Top achievements
Rank 1
Iron
Iron
Iron
ixen asked on 30 Sep 2021, 08:59 AM
Hi

I have an complex object initialize from Rest WebService with many fields and there is an Date fiel, but i could init it with patch value to kendo-datepicker

Could you help me



Regards

1 json object from  MyService
{
    "profilId": 50531,
    "surname": "3454",
    "name": "11",
    "date": "2027-12-30"
...
...
..
...
...

}

2 html

 <kendo-datepicker id = "date" formControlName = "date" class = "pull-left" >  </kendo-datepicker>

    3 component
    export class DossiersDetailDossierTabsheetSommaireFormComponent implements OnInit {
    constructor(private formBuilder: FormBuilder,
        private activatedroute: ActivatedRoute,
        private router: Router,
        private dps: MyService ) {}

    ngOnInit() {
        this.registerForm = this.formBuilder.group({
            profilId: [''],
            surname: [''],
            name: [''],
date: ['']
        });

        this.dps.getData(this.id)
        .pipe(first())
        .subscribe(x => this.registerForm.patchValue(x)); //ERROR ON Date field
    }
}
Christian
Top achievements
Rank 1
commented on 30 Sep 2021, 11:26 AM

The Date must be a date type 
try new Date(date)

 

1 Answer, 1 is accepted

Sort by
0
ixen
Top achievements
Rank 1
Iron
Iron
Iron
answered on 30 Sep 2021, 12:53 PM

Hi

 

Like this ?

not running ?


    ngOnInit() {
        this.registerForm = this.formBuilder.group({
            profilId: [''],
            surname: [''],
            name: [''],
date: ['',new Date()],
        });

Tags
DatePicker Forms
Asked by
ixen
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
ixen
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or