当我提交表单并将其转换为字符串时,我目前正在返回一个对象,因为我的服务需要一个字符串值。
但是...当我调用该函数时,它会返回我的表单对象并将其放入“值”对象中,并且我不确定如何仅调用“值”对象中的对象。任何人都可以帮忙吗?
我的提交功能:
submitEvent(value: any): void {
// this.loading = true;
let stringEvent: string = JSON.stringify({value});
this.eventService.create(stringEvent).subscribe(result => {
if (result === true) {
this.loading = false;
} else {
this.error = 'Username or password is incorrect';
this.loading = false;
}
});
}
我的表格:
<form [formGroup]="eventForm" class="form-horizontal style-form" name="form" (ngSubmit)="submitEvent(eventForm.value)" novalidate>
它返回什么:
{
"value": {
"name": "",
"description": "",
"attendeeCountMax": "",
"attendeeCountMin": "",
"costMax": "",
"responseDeadline": "",
"eventDates": {
"startDate": "",
"endDate": "",
"type": 1
},
"location": {
"cost": 0,
"costDescription": "string",
"costType": "string",
"description": "string",
"name": "string",
"uri": "string"
},
"startDate": "2016-11-11T16:11:11.773Z"
}
}
我只想要“价值”对象里面的东西