Angularjs 如何在ionic中的警报中显示数据表单http请求
我试图显示来自http请求的数据并在警报中显示它,但我得到的只是[object object],在我的控制台中,我可以看到我的数据[{code:“MNV”}],但我不知道如何在alters中显示Angularjs 如何在ionic中的警报中显示数据表单http请求,angularjs,ionic-framework,ionic2,Angularjs,Ionic Framework,Ionic2,我试图显示来自http请求的数据并在警报中显示它,但我得到的只是[object object],在我的控制台中,我可以看到我的数据[{code:“MNV”}],但我不知道如何在alters中显示 Coupons(offer,code){ this.peopleservice.getCoupons(offer,code).subscribe(data=>this.Code=data); let prompt = this.alertCtrl.create({
Coupons(offer,code){
this.peopleservice.getCoupons(offer,code).subscribe(data=>this.Code=data);
let prompt = this.alertCtrl.create({
title: 'code',
message:this.Code,
buttons:[
{
text: 'Cancel',
handler: data => {
console.log(this.Code)
}
}
]
}
);
prompt.present();
你是说你想在警报中显示MNV 如果是,您需要这样做
let prompt = this.alertCtrl.create({
title: 'code',
message: this.Code.code,
buttons:[
{
text: 'Cancel',
handler: data => {
console.log(this.Code)
}
}
]
}
);
prompt.present();
您必须在传递给subcribe的函数中创建并呈现警报,因为它是一个流,如果您调用此服务(GetCouples),并且不等待它返回并创建警报,那么您还没有值
Coupons(offer,code){
this.peopleservice.getCoupons(offer,code)
.subscribe( data => {
let prompt = this.alertCtrl.create({
title: 'code',
message: data.message, //or anything else
buttons:[
{
text: 'Cancel',
handler: data => {
}
}
]
});
prompt.present();
});
}
我尝试按照您所说的那样执行data.code,但我的警报为空,我尝试登录以查看其中的内容,我得到了undefinedit,但我得不到。/alertCmp类由undefined引起的alertCmp不受反对(评估此.code.code)
Coupons(offer,code,Store){
this.peopleservice.getCoupons(offer,code,Store)
.subscribe(data =>{this.Coode = data[0].code
let prompt = this.alertCtrl.create({
title: 'code',
message: this.Code,
buttons:[
{
text: 'Cancel',
handler: data => {
}
}
]
})
prompt.present();
},resError=>this.dataError(2));
}