2017-09-24 19 views

回答

0

这是工作:

this.http.post('my-url', postParams, options) 
    .subscribe(res => { 
     console.log(res.json());   
    }, error => { 
     let err = error.json(); // this line added 
     console.log(err); 
    }); 
1

你可以达到同样的使用map运营商,像这样:

this.http.post('my-url', postParams, options) 
    .map(res => res.json()) // Get the body of the response here :) 
    .subscribe(response => { 
     console.log(response); // <-- Use the response object directly   
    }, error => { 
     console.log(error);  // <-- Use the error object directly 
    }); 
+0

感谢,但你的代码是一样的我的代码有问题,这只是使用: error.json() –

+1

是@ M.Hajavi,它非常相似,但推荐的方式来获得响应(和错误)的主体是通过使用'map'运算符,而不是调用'json )'方法都在响应和错误对象中。 – sebaferreras

+0

我试过了,但它不起作用 –

相关问题