I am trying to display a data from http request and display it in alert
but all I get is [object object] and in my console, I can see my data [{code: “MNV”}] but I
don’t know how I can make display in the alert
public Code:any;
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();
In the first try I got undefined in the console and an empty alert and in
the second try the I got [{code: “MNV”}] in the console and an [object object ] in the alert
You have two problems. First is what @FnnHuman was alluding to, which is that you must move the creation of the alert inside the subscription in order to be able to rely on code being set. Secondly, you are responsible for converting the object into a string before you pass it as a message.