如何在离散

时间:2017-06-27 12:07:01

标签: angularjs ionic-framework ionic2

我正在尝试显示来自http请求的数据并将其显示在警报中,但我得到的只是[对象对象],在我的控制台中,我可以看到我的数据[{code:“MNV”}]但我不知道我知道如何在改变中显示

  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();

3 个答案:

答案 0 :(得分:0)

所以你说你想在警报中显示MNV吗?

如果是,您需要这样做

let prompt = this.alertCtrl.create({

         title: 'code',
         message: this.Code.code,

         buttons:[
             {
                text: 'Cancel',
  handler: data => {

    console.log(this.Code)

             }
             }
         ]
    }

    );
    prompt.present();

答案 1 :(得分:0)

您必须在传递给订阅的功能中创建并显示您的提醒,因为它是一个流,如果您调用此服务(getCoupons)并且不等待此返回并创建提醒,则还没有价值观。

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();

    });
}

答案 2 :(得分:0)

    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));

}