首页 > 解决方案 > 使用firebase在点击时显示详细信息

问题描述

我想通过点击 firebase 键的元素来显示地址的详细信息。我可以用 id 来做,但不能用 push 的键。感谢您的回访,因为我不知道如何使用密钥

我的地址表

我的地址表

服务地址

 getSingleAdresse(id: number){
        return new Promise(
          (resolve, reject) =>{
            firebase.database().ref('/adresse/' +id).once('value').then(
              (data) => {
                resolve(data.val());
              }, (error) => {
                reject(error);
              }
            );
          }
        );
      }

列表页.html

<ion-card *ngFor="let item of adresses | keyvalue ; let i = index" (click)="onViewAdresse(i)">
         <div><b>{{item.value.prenom}} {{item.value.nom}}</b></div>
</ion-card>

单个地址.ts(检索元素的页面)

ngOnInit() {
    this.adresse = new Adresse ('','', '', '', '', '');
    const id = this.route.snapshot.params['id'];
    this.adresseService.getSingleAdresse(+id).then(
      (adresse: Adresse) => {
        this.adresse = adresse;
      }
    );
  }

}

标签: javascriptangularfirebaseionic-frameworkfirebase-realtime-database

解决方案


推荐阅读