Angular 2 Form Serialization Into JSON Format

前端 未结 3 1622
无人共我
无人共我 2021-02-05 15:14

I am having a little bit of trouble creating my Angular 2 form and converting the submitted data into JSON format for the use of submitting it to my API. I am looking for someth

3条回答
  •  长情又很酷
    2021-02-05 15:29

    You can use JSON.stringify(form.value):

    submit() {
      let resource = JSON.stringify(this.form.value);
    
      console.log('Add Button clicked: ' + resource);
    
      this.service.create(resource)
        .subscribe(response => console.log(response));
    }
    

    Result in Chrome DevTools:

提交回复
热议问题