如何在angular2中获取http响应状态+返回的数据
我正在尝试在angular2/ionic2中使用Http 我的服务代码是如何在angular2中获取http响应状态+返回的数据,angular,Angular,我正在尝试在angular2/ionic2中使用Http 我的服务代码是 getImageQuestionsFromServer(id:string){ let questions = this._http.get(`http://abcd.com/cbsapp/package_content/${id}/image_questions.json`).map((res: Response) => res.json()); return questions; }
getImageQuestionsFromServer(id:string){
let questions = this._http.get(`http://abcd.com/cbsapp/package_content/${id}/image_questions.json`).map((res: Response) => res.json());
return questions;
}
我的组件代码是
this._userDataService.getImageQuestionsFromServer(this.passedPackage.id)
.subscribe(
(data) => console.log(data.status),
(err) => console.log(err)
)
我不知道如何检查我的组件中的Http状态代码。请提供帮助。服务方法:
getImageQuestionsFromServer(id:string){
return this._http.get(`http://abcd.com/cbsapp/package_content/${id}/image_questions.json`);
}
组件法:
this._userDataService.getImageQuestionsFromServer(this.passedPackage.id)
.subscribe(
(response) => {
let status = response.status
let data = response.json();
},
(err) => console.log(err)
);