0
在我的离子项目中,我使用API获取航班详细信息。在该API中,它具有名为“airportResources” 的对象并且具有4个值(出发终端,到达终端,出发网关,到达网关)。但有时这个对象在api中不可用,或者所有的值都不可用(这意味着它有时仅包含出发端,或到达终端或任何两个或三个值)。 我的问题是,当我尝试显示此值时,它显示错误。 我可以如何处理这个问题。下面包括在响应的 屏幕快照(此图像的airportResources对象中只有2个值) 如何处理API数据
TS代码:
enter code here
get_arrivalflights(){
var communicationParams = {
showLoader: true,
reqUrl: "",
reqBody: {},
callBackSuccess: (response) => {
console.log(response);
this.objectData = response.flightStatuses;
},
callBackFailure: (response) => { console.log("failure dude"); console.log(response); }
};
this.restservice.makeGetRequest(communicationParams);
}
HTML:
<div class="col" style="font-size: 18px;text-align: center">{{item.airportResources.departureTerminal}}</div>
阿比电话中提供:
makeGetRequest(communicationParams: any) {
this.baseUrl = " the url i want to call ";
var loader;
if (communicationParams.showLoader == true) {
loader = this.loadingController.create({
content: ""
});
loader.present();
}
this.http.get(this.baseUrl + communicationParams.reqUrl)
.map(response => response.json())
.subscribe(communicationParams.callBackSuccess, function(respone) {
if (communicationParams.showLoader == true) {
loader.dismiss()
}
communicationParams.callBackFailure(respone);
},
() => {
console.log('Authentication Complete');
if (communicationParams.showLoader == true) {
loader.dismiss()
}
});
}