Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用angularFire防止重复结果_Angular_Typescript_Firebase_Ionic3_Angularfire - Fatal编程技术网

如何使用angularFire防止重复结果

如何使用angularFire防止重复结果,angular,typescript,firebase,ionic3,angularfire,Angular,Typescript,Firebase,Ionic3,Angularfire,我有这样的firebase db: "cardsList" : { "tok_1BVGrNCM8UWO9kaul5P0MoQa" : { "cardHolder" : "John", "expMonth" : 12, "expYear" : 2020, "number" : "42** **** **** **43", "pi

我有这样的firebase db:

    "cardsList" : {
            "tok_1BVGrNCM8UWO9kaul5P0MoQa" : {
              "cardHolder" : "John",
              "expMonth" : 12,
              "expYear" : 2020,
              "number" : "42** **** **** **43",
              "pin" : 1234
            },
              "tok_7BTErNCM8UWO9kaul5P0MoQa" : {
              "cardHolder" : "Eliott",
              "expMonth" : 12,
              "expYear" : 2020,
              "number" : "44** **** **** **49",
              "pin" : 1234
            }
}
我使用以下方法获得阵列中每个卡的结果:

this.firebaseProvider.list('patientList/'+this.profileMember.idPatient+'/cardsList')
    .subscribe(cards=> cards.forEach(card=> {
      console.log(card.number)
      this.cardsList.push({'number': card.number})
      }))
在我的html中,我使用以下内容显示结果:

<div *ngFor="let card of cardsList">
{{card.number}}
</div>
更新后

42** **** **** **43
44** **** **** **49
42** **** **** **43
44** **** **** **49
42** **** **** **43
如何预防

欢迎任何帮助


Alex.

你只需将
可观察的
转换为
承诺
即可避免它,如下所示

import 'rxjs/add/operator/toPromise';

this.firebaseProvider.list('patientList/'+this.profileMember.idPatient+'/cardsList').toPromise().then(cards=> cards.forEach(card=> {
    this.cardsList.push({'number': card.number})
}))

您好,它返回:toPromise()不是一个函数。toPromise未定义。谢谢Sam!你的解决方案是有效的。我还有一个问题,也许你也能帮我;-)如果我使用此代码:this.paymentList=this.firebaseProvider.list('patientList/'+this.profileMember.idPatient+'/paymentList').map((cards)=>{return cards.map(card=>{return this.firebaseProvider.object('patientList/'+this.profileMember.idPatient+'/paymentList/'+card.key)})这是一种将结果推入如下数组的方法:this.cardsList.push(paymentList的结果)?我认为上面的
code
将不起作用,因为它的
async
特性。希望你能把它当作另一个问题不?这样就有更好的能见度了。