问题
I have a collection inside firestore database that consists of several data fields and references. Structure looks like this:
firstCollection document sample
{
name: 'parent',
//more fields,
second: //reference to document from second collection
}
secondCollection referenced document sample
{
title: 'document title',
more: 3456,
etc: '...'
}
I have angular application with angularfire2 library included. In one of my html files I need to print data from the first collection including some field values from document of the second collection. Document from the second collection has valid reference from the first collection (see above). This is what I want to do:
<div *ngFor="let first of firstCollection | async">
this works - {{first.name}}
Now the question is, How can I access document data from the second collection here?
What I need is something like the following:
{{first.second.title}} - this doen't work because 'second' is just reference
</div>
回答1:
Reading data from Cloud Firestore is shallow. This means when you read the first document, you have not yet loaded any of the data in the second document (to which you have a reference).
You'll have to perform another get()
or listen operation on that reference in order to get the data.
https://github.com/angular/angularfire2/blob/master/docs/firestore/documents.md
来源:https://stackoverflow.com/questions/46663160/access-data-from-document-referenced-inside-firestore-collection