我正在尝试将数据发布到Angular的后端Node js文件中.表单提交后,函数调用:
cmdSubmit() : void
{
console.log(this.cli);
this.Cliservice.postdata(this.cli)
.then(clidata => this.clidata.push(clidata),
error => this.errorMessage = <any>error);
}
Run Code Online (Sandbox Code Playgroud)
postdata功能代码:
postdata(obj: any): Promise<any> {
alert('hello');
let body = JSON.stringify({ obj });
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.runUrl, body, options)
.map(this.extractData)
.catch(this.handleError);
/*return this.http.post(this.runUrl, body, options)
.map(this.extractData)
.catch(res => {
// do something
// To throw another error, use Observable.throw
return Observable.throw(res.json());
});*/
}
private extractData(res: Response) {
let …Run Code Online (Sandbox Code Playgroud)