在 Angular 项目中,我有一个包含 FormControls 的 FormArray,我不知道如何对这个 FormArray 进行字符串化以便将其发送到服务器。这是代码、Submit 方法和我制作 Observable 的服务。请帮忙。
onSubmit(){
let formControls = new FormArray([]);
formControls = <FormArray>this.reviewForm.get('controlArray');
this.formService.createForm(formControls)
.subscribe(
data => console.log(data),
error => console.error(error)
);
this.reviewForm.reset();
// console.log(formControls);
}
@Injectable()
export class FormService {
constructor(private http: Http) {}
createForm(formControls: FormArray) {
const body = JSON.stringify(formControls); //this gives error
const headers = new Headers({'Content-Type': 'application/json'});
return this.http.post('http://localhost:3000/api/form', body, {headers: headers})
.map((response: Response) => response.json())
.catch((error: Response) => Observable.throw(error.json()));
}
}