简体   繁体   English

离子2从ts文件引用html文件中的值?

[英]Ionic 2 reference a value in html file from ts file?

I am querying a set of data from firebase and successfully pulled a list of data to my html page. 我正在从Firebase查询一组数据,并成功将数据列表提取到了html页面。 Is there any way to reference the corresponding item.uid value from the html page in my onViewProfile function so that I can push it to another page? 有什么办法可以从onViewProfile函数中的html页面引用相应的item.uid值,以便可以将其推送到另一个页面? Thanks. 谢谢。 emphasized text 强调文字

HTML file 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 file 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));
}
}

Well it is so simple that I feel I'm not getting it right. 好吧,它是如此简单,以至于我觉得我做错了。

You have to pass it as a parameter like this 您必须像这样将其作为参数传递

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

Then your ts will turn into 然后你的ts会变成

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


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM