小编Rav*_*ja 的帖子

Angular Http不工作

我正在尝试将数据发布到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)

http typescript angular2-services angular

4
推荐指数
1
解决办法
1225
查看次数

标签 统计

angular ×1

angular2-services ×1

http ×1

typescript ×1