ERROR Missing number at position 0 when using setValue angular 4
The thing is that PrimeNG date picker expects to receive instance of Date
class as a value and it returns instance of a Date
class as value. So that's why your attempts to put object of other types in there failed.
It's not clear why you attempt to call setValue()
in the submit handler.
If your goal is to modify value programmatically follow suggestion from VincenzoC in comments - modify object and transform it back to Date
object before passing it to setValue()
.
let newDate: Date = moment(this.form.get('purchaseDate').value).add(5, 'days').toDate();
this.form.get('purchaseDate').setValue(newDate);
If your goal is to format Date
object for submitting to backend, you don't need to call setValue()
at all. Format Date
object to string and pass this string instead of Date
object to the backend API. If you submitting whole value
object from form you can modify it this way before submitting:
let newDate: string = moment(this.form.get('purchaseDate').value).format('YYYY.MM.DD');
let dataForBackend = { ...this.form.value, purchaseDate: newDate };
this.myBackend.sendData(dataForBackend);