提交表单Angular 6上的空对象

时间:2018-11-02 07:11:44

标签: angular http

我有以下代码:

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代码

0 个答案:

没有答案