Ionic 2引用ts文件中的html文件中的值?

时间:2017-06-30 21:17:57

标签: javascript html ionic2

我正在从firebase查询一组数据,并成功将数据列表提取到我的html页面。有没有办法从我的onViewProfile函数中的html页面引用相应的item.uid值,以便我可以将它推送到另一个页面?谢谢。强调文字

HTML文件

<ion-content padding>
   <ion-label>Type</ion-label>
    <ion-select [(ngModel)]="type" (ionChange)="searchPitchesByType(type)">
      <ion-option value="test1">test1</ion-option>
      <ion-option value="test">test</ion-option>
    </ion-select>
<ion-list>
    <ion-item *ngFor="let item of pitches | async">
      Name: {{ item.name }}
      <p>
        Description:{{ item.description }}
      </p>
      <p>
        uid:{{ item.uid }} 
      </p>
      <button right ion-button icon-only (click)="onViewProfile()">
        <ion-icon name="add"></ion-icon>
      </button>
   </ion-item>
  </ion-list>

</ion-content>

TS文件

export class DiscoverPage {
   public pitches: FirebaseListObservable<any>;

  constructor(
  private navCtrl: NavController,
   private loadingCtrl: LoadingController,
   private popoverCtrl: PopoverController,
    public afDatabase: AngularFireDatabase
    ) {this.pitches = afDatabase.list('/Pitches/');}

searchPitchesByType(type: string){

  this.pitches = this.afDatabase.list('Pitches', {
    query: {
      orderByChild: 'type',
      equalTo: type

    }

  })



}
onViewProfile() {
  let data = {
    uid: **(uid that corresponds to the uid in html)**


  }
    console.log(this.navCtrl.push(ViewProfilePage, data));
}
}

1 个答案:

答案 0 :(得分:2)

这很简单,我觉得我做得不对。

您必须将其作为参数传递给

<ion-item *ngFor="let item of pitches | async">
      Name: {{ item.name }}
      <p>
        Description:{{ item.description }}
      </p>
      <p>
        uid:{{ item.uid }} 
      </p>
      <button right ion-button icon-only (click)="onViewProfile(item)">
        <ion-icon name="add"></ion-icon>
      </button>
</ion-item>

然后你的ts将变成

onViewProfile(item) {
  let data = {
    uid: item.uid


  }
    console.log(this.navCtrl.push(ViewProfilePage, data));
}