Is there any significant difference between using patchValue or setValue to set the value on a form ? Also is there any difference or best practice regarding using moment or date obj ?
if(startDate) {
const date = moment(startDate).toDate();
this.form?.patchValue({ startDate: date });
}
if(endDate) {
const date = new Date(endDate);
this.form.get('endDate').setValue(date);
}
Either way it works as expected for me , so I am just wondering .
Moment is a matter of preference, you don't NEED it but you can sure use it.
As for patch VS set, the difference is mainly on form groups rather than form controls : setValue requires all fields to be set, but patchValue accepts a partial of all the fields that are expected.