2017-02-25 31 views
0

我在這裏要通過商店ID作爲1和0.Here STORE_ID = '1' 是班加羅爾和STORE_ID = '0' 海得拉巴..如何在popover中顯示名稱?

這裏是我的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> 

這裏如果我要點擊「bengaluru」意味着它必須在我的popover中顯示該名稱,並且與「hyderabad」相同。

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

    } 

} 

,如果任何機構都知道,請回復此..

+0

是什麼問題? –

+0

問題是,當我點擊選擇城市,它顯示下拉右下拉下來,如果我點擊bengaluru或海得拉巴它必須顯示該名稱 – balu

+0

在popover意味着選擇城市就像那樣它必須顯示 – balu

回答

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