Firebase / Angularfire2: nested data nodes in firebase

喜夏-厌秋 提交于 2019-12-13 03:35:34

问题


i've got a firebase database. a node called /config// which holds userspecific data. i now want to add a subtree to the userdata with a list of cars, like /config//cars/:

"config" : {
    "NE5AwHcxKofMPKRCAvny5Re4MtG3" : {
      "geburtstag" : "2017-06-04",
      "nachname" : Mueller",
      "cars" : {
        "-Krr2-DC1uoqCvgVJhFL" : {
          "name" : "Ford Mustang"
        },
        "-Krue4_5kJQhis-3Qg1X" : {
          "name" : "Toyota Supra"
        }
      }
    }

i created a observable binding to /config/

this.$ref = this.database.object('/config/' + uid);
this.data = this.$ref.subscribe();

i can access the data of the main config-node and bind it with angular, but a ngFor on the Cars subnode doesn't work. Am i structuring my data wrong or do I need some kind of mapping here?

the html part:

<ion-item *ngFor="let car of data.cars | async">
    {{car.name}}
 </ion-item>

回答1:


You're assigning data to your subscription while you should be assigning it to the observable:

cars: FirebaseListObservable<any[]>;
this.cars = this.database.list(`/config/${uid}/cars`);

Now you can call your async data in your ngFor loop:

<ion-item *ngFor="let car of cars | async">
  {{ car.name }}
</ion-item>


来源:https://stackoverflow.com/questions/45772562/firebase-angularfire2-nested-data-nodes-in-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!