-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Retrieving list data with items id #1562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It's not very clear in the documentation, but if you look in the example app here: https://github.com/angular/angularfire2/blob/master/docs/rtdb/lists.md you will see the following code:
Then you have access to the key without storing it in the items.... |
Thank you @jymdman I finally made it work with your solution. The most anodin use of angular lists is to display it and access individual items. The only way to do this is by using something similar to: <div *ngFor="let item of items" (click)="doSomething(item.id)">
...
</div> Personally, I think your sample code should be in a dedicated section and should be the first thing someone discovering AngularFire should see in the documentation. Anyway, thank you a lot, it really helped. |
this._db
.collection('collection')
.snapshotChanges()
.pipe(first())
.subscribe((res: DocumentChangeAction<any>[]) => {
res.forEach((result: DocumentChangeAction<any>) => {
const data = result.payload.doc.data();
this.extendedItems.push({
id: result.payload.doc.id,
data
})
});
}); |
Thanks for the hint. But in this case we have to navigate each items to parse the id. Do we have any other options to directly bind the items to Observable<Data[]>? |
I am very new to AngularFire. Trying to accomplish something similar to Angular ToH tutorial (e.g. retrieving/displaying a list and accessing item details by id) using AngularFireDatabase, the only way I found was:
I have been looking for days for a way to do this with a single request, with no result. Finally, I found a solution in #199 (closed):
At the time of item creation:
If I missed something in the documentation, I apologize for this issue. If not, I am very surprised that there is no simple way to retrieve items in a list with their reference.
If I am not wrong about it, I would either createPushId() to be documented or a simple way to retrieve list with items id. But using createPushId implies key redundancy in database, so it would not be the best solution in my opinion.
Version info
Angular: angular/[email protected]
Firebase: 4.12.1
AngularFire: 5.0.0-rc.5-next
The text was updated successfully, but these errors were encountered: