Angularfire5 - 获取列表中实时数据库文档的密钥 - #askfirebase
Angularfire5 - Get the key of Realtime database documents in list - #askfirebase
我正在加载一个列表并将其传递给一个组件以呈现信息。我需要的物品之一是身份证。我怎么能在列表中看到它。我已经看到了 documentation 但它没有帮助。它只显示父密钥。
this.allWorkouts = this.afDb.list<IWorkout>('/workouts')
.valueChanges()
.take(1)
.map((array) => array.reverse()) as Observable<IWorkout[]>;
<ion-card *ngFor="let workout of allWorkouts | async">
<card-workout [workout]="workout"></card-workout>
</ion-card>
要获得密钥,您需要订阅可观察对象,然后以这种方式打印:
suscribe(snapshot => { snapshot.$key })
如果你需要打印成 *ngFor 你应该使用:
workout.$key
在 AngularFire 5.0 版本中,您需要 use snapshotChanges()
if you want to get access to the key。
valueChanges()
仅适用于基本用例,您只关心 JSON 树。
我正在加载一个列表并将其传递给一个组件以呈现信息。我需要的物品之一是身份证。我怎么能在列表中看到它。我已经看到了 documentation 但它没有帮助。它只显示父密钥。
this.allWorkouts = this.afDb.list<IWorkout>('/workouts')
.valueChanges()
.take(1)
.map((array) => array.reverse()) as Observable<IWorkout[]>;
<ion-card *ngFor="let workout of allWorkouts | async">
<card-workout [workout]="workout"></card-workout>
</ion-card>
要获得密钥,您需要订阅可观察对象,然后以这种方式打印:
suscribe(snapshot => { snapshot.$key })
如果你需要打印成 *ngFor 你应该使用:
workout.$key
在 AngularFire 5.0 版本中,您需要 use snapshotChanges()
if you want to get access to the key。
valueChanges()
仅适用于基本用例,您只关心 JSON 树。