我有以下代码:
html:
<div id="add">
<span>ADD ITEM</span>
<form #formRef ="ngForm" (ngSubmit)="addData(formRef.value)">
<input type='text'>
<button type='submit'>Add</button>
</form>
</div>
ts:
addData(data: NgForm) {
console.log(data);
this.http.addData(data).subscribe(
(data: any) => this.getData()
);
}
service.ts:
addData(data: NgForm) {
this.count++;
const newData = {
'name': data,
'id': this.count
};
return this.http.post<Data>(this.Url, data, this.httpOptions);
}
我正在提交表单,当我控制台数据时,它将打印空对象而不是表单数据。我要去哪里错了?
更新:
getData() {
this.http.getData().subscribe(
(data: any) => {
this.randData = data;
});
}
添加了getData代码