相关疑难解决方法(0)

ERROR使用setValue angular 4时缺少位置0处的数字

我正在使用Angular 4 with reactiveforms,momentjsprimeng calendar我正在使用setValue并尝试使用patchValue包含Date的reactiveForm字段.此日期已通过primeng日历创建.

purchaseDate: Sat Sep 02 2017 00:00:00 GMT+0100 (GMT Daylight Time)

我使用这个'日期'做了几件事,然后onSumbit的形式我把日期转换momentjs成一个干净的格式准备后端接受(即YYYY.MM.DD)使用.moment().format(....

但是,当我运行时,.setValue我得到以下控制台错误ERROR Missing number at position 0,无法弄清楚原因.

// convert the date
let newDate = moment(this.form.get('purchaseDate').value).format('YYYY.MM.DD');
// let newDate = moment(this.form.get('purchaseDate')).format('YYYY.MM.DD');
// with or without .value - display the same below (2017.09.01)
console.log(newDate); // 2017.09.01
this.form.get('purchaseDate').setValue(newDate);

// if I create a seperate (empty) reactiveForms field to test against
this.form.get('testField').setValue(newDate) // …
Run Code Online (Sandbox Code Playgroud)

javascript momentjs primeng angular angular-reactive-forms

10
推荐指数
1
解决办法
4065
查看次数