从master
文件中,我以[{1}}的形式从app.component.ts
获取数据,但[Object Object]
给出了空白结果,当我尝试从UI访问报告网址,我收到此错误:alert(this.datas);
。
有人可以提供解决方案吗?
以下是必要的文件:
app.component.ts类(摘录)
alert(this.datas.ReportDtDataForMAPP);
app.html(节选)
Cannot read property 'URL' of undefined
myMobileDataService.ts类
//...
//Lines of code
//...
this.myMobileDataService.checkAuthorization(this.enterpriseId,v2Token)
.subscribe(
response => {
this.datas = response;
JSON.stringify(this.datas);
alert(this.datas);
alert(this.datas.ReportDtDataForMAPP);
if(this.datas == null || this.datas == ""){
this.nav.setRoot(this.accessDeniedPage, {showFooter : false});
} else {
this.nav.setRoot(this.homePage, {showFooter : false});
}
},
err => {
console.log("Error here!:"+err);
}
);
},
//...
//Lines of code
//...
OpenReport(report : any)
{
let list = this.datas.ReportDtDataForMAPP;
let newList = list.filter((t) => t.SubReport == report);
JSON.stringify(newList)
this.myURL = newList[0].URL;
this.openUrl(this.myURL);
}
//...
//Lines of code
//...
http post请求以这种形式提供数据:
//...
//Lines of code
//...
<ion-grid>
<ion-row>
<ion-col class="reportHeader reportHeaderPadding"><strong>AAA</strong></ion-col>
</ion-row>
<ion-row text-center>
<ion-col (click)="OpenReport('MURLAAA')" tappable><img src = "assets/icon/AAA.png" alt = "Image Not Available" class = "homeImages"></ion-col>
<ion-col (click)="OpenReport('MURLBBB')" tappable> <img src = "assets/icon/BBB.png" alt = "Image Not Available" class = "homeImages"></ion-col>
<ion-col (click)="OpenReport('MURLCCC')" tappable> <img src = "assets/icon/CCC.png" alt = "Image Not Available" class = "homeImages"></ion-col>
</ion-row>
<ion-row text-center class="addBorder">
<ion-col (click)="OpenReport('MURLAAA')" tappable class="reportName">AAA</ion-col>
<ion-col (click)="OpenReport('MURLBBB')" tappable class="reportName">BBB</ion-col>
<ion-col (click)="OpenReport('MURLCCC')" tappable class="reportName">CCC</ion-col>
</ion-row>
//...
//Lines of code
//...
答案 0 :(得分:0)
调用此函数时:
OpenReport(report : any)
{
let list = this.datas.ReportDtDataForMAPP;
let newList = list.filter((t) => t.SubReport == report);
JSON.stringify(newList)
this.myURL = newList[0].URL;
this.openUrl(this.myURL);
}
由于subscribe
为异步:https://angular.io/guide/http
在javascript中查找异步编程