在离子本机HTTP获取请求中出现错误“类型错误:无法将未定义或null转换为对象”
getDetail() {
let loading = this.loadingCtrl.create({
spinner: "bubbles"
});
loading.present();
var myData = {};
let headers = {
"Content-Type": "application/json; charset=utf-8",
"cache-control": "no-cache"
};
//I have tried to add time out but not working
this.http.setRequestTimeout(5);
this.http
.get(global.apiUrl + "homepagedetails", myData, headers)
.then(data => {
this.tmpDetail = JSON.parse(data.data);
})
.catch(error => {
//==> getting error alert here
alert(JSON.stringify(error, Object.getOwnPropertyNames(error)));
loading.dismiss();
});
}