如何在popover中显示名称?

时间:2017-02-25 05:10:43

标签: angular ionic2

在这里,我要将商店ID传递为1和0.Hhere store_id =' 1'是bengaluru和store_id =' 0'作为海德拉巴..

这是我的HTML代码:

home.ts

presentPopover(myEvent) {
  let popover = this.popoverCtrl.create(Popoverpage);
  popover.present({
    ev: myEvent
  });
}

home.html

<ion-header>

  <button ion-button icon-only (click)="presentPopover($event)" >
    Choose City
    <ion-label>{{cityname}}</ion-label>
    <ion-icon name="arrow-dropdown" item-right></ion-icon>
  </button>

</ion-header>

如果我要点击&#34; bengaluru&#34;意味着它必须在我的popover中显示该名称,并且与&#34; hyderabad&#34;相同。

popoverpage.ts

@Component({
    template: `
        <ion-list>
          <button ion-item (click)="store()">Bengaluru</button>
          <button ion-item (click)="fun()">Hyderabad</button>
        </ion-list>
      `
})

export class Popoverpage{
    store_id
    cityname


    constructor(public viewCtrl: ViewController,
                public navCtrl: NavController,
                public rest: Rest,
                public logger: Logger) {
    }

    store() {
        let  storeObj={
            store_id: '1'
        }

        this.logger.debug("checking the  " +JSON.stringify(storeObj));

        this.rest.post('/store',storeObj)
            .subscribe(result => {
                this.logger.debug("checking the data "+JSON.stringify(result));
                if(result.status == '1'){
                    this.logger.info("success callback");
                    this.cityname="Bengaluru";

                    //this.navCtrl.pop();
                    this.viewCtrl.dismiss();

                }
                else{
                    this.logger.info("error callback");
                    this.viewCtrl.dismiss();
                }
            })

    }

    fun() {
        let  storeObj={
            store_id: '0'
        }

        this.logger.debug("checking the  " +JSON.stringify(storeObj));

        this.rest.post('/store',storeObj)
            .subscribe(result => {
                this.logger.debug("checking the data "+JSON.stringify(result));
                if(result.status == '1'){
                    this.logger.debug("success callback");
                    this.cityname="Hyderabad";
                    //this.navCtrl.pop();
                    this.viewCtrl.dismiss();
                }
                else{
                    this.logger.debug("error callback");
                    this.viewCtrl.dismiss();
                }
            })

    }

}

如果有人知道请回复此事。

1 个答案:

答案 0 :(得分:0)

我不确定为什么你点击按钮点击方法“存储”和“有趣”,但请记住,你总是可以将字符串传递给你的点击处理程序方法。也许是这样的:

<button ion-item (click)="clicked('bangaluru')">Bengaluru</button>
<button ion-item (click)="clicked('hyderabad')">Hyderabad</button>

clicked (e) {
  console.log('clicked ' + JSON.stringify(e));
  this.currentCity = e; 
}

这是plunkr demo