【发布时间】:2018-08-28 17:10:50
【问题描述】:
开发人员您好,我正在尝试使用 promise 从我的 API 中检索数据,并在我的函数中使用这些值....这是我在服务中的函数
getetudiant() {
return new Promise((resolve, reject) => {
this.http.get('http://localhost/eportfolio/etudiantprofile.php')
.map(res => res.json())
.subscribe(data => {
resolve(data);
}, error => {
reject(error);
})
})
}
}
这是我在页面上的调用。问题是在函数之外调用 etudiantstage 它给了我一个空数组
}
getAllStageItems(){
this.etprofile.getetudiant().then((data: any) => {
this.etudiantstage = data
console.log(this.etudiantstage);
});
console.log(this.etudiantstage);
for(let item in this.etudiantstage){
console.log(this.etudiantstage[item].cin);
if(this.etudiantstage[item].cin == this.cin)
this.validerAffiche = true;}
}
第一个 console.log(this.etudiantstage) 工作,但第二个不工作 Screen Shot 谁能帮我解决这个问题,拜托!
【问题讨论】:
标签: angular api ionic-framework promise provider