我正在尝试在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;
}
我的组件代码是
this._userDataService.getImageQuestionsFromServer(this.passedPackage.id)
.subscribe(
(data) => console.log(data.status),
(err) => console.log(err)
)
我不知道如何检查组件内的Http状态代码。请帮忙。
答案 0 :(得分:1)
服务方式:
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)
);