I'm trying to parse fetched data from firebase at Angular (Typescript).
My JSON data looks like this in firebase:
"customer" : {
"customerId1" : {
"documents" : {
"documentId1" : {
"documentName" : "file1.pdf",
"documentUrl" : "someUrl1"
},
"documentId2" : {
"documentName" : "file2.pdf",
"documentUrl" : "someUrl2"
}
},
"email" : "[email protected]",
"name" : "Customer 1",
},
"customerId2" : {
"documents" : {
"documentId3" : {
"documentName" : "file3.pdf",
"documentUrl" : "someUrl3"
},
"documentId4" : {
"documentName" : "file4.pdf",
"documentUrl" : "someUrl4"
}
},
"email" : "[email protected]",
"name" : "Customer 2",
}
}
As you can see, each customer has 3 properties, documents, email and name at the first level. At the second level, the document property has nested property documentName and documentUrl. And for parsing customer data I used the following code.
customer.component.ts:
...
export class CustomerComponent implements OnInit {
customerObservable: Observable<any[]>;
customerList: Customer[];
constructor(db: AngularFireDatabase) {
// Listen to customer data
this.customerObservable.subscribe(data => {
this.customerList = data;
});
}
}
...
With this code I can fetch and iterate data with the ngFor directive at html with customerList variable. The question is, how can I achieve something like this?
// Variable that contains array of an array of customer's document array
documentList: Document[][];
// Or this
// Variable that holds customer's documents
customerDocuments: Document[];
// Where Document model looks like this
export class Document {
public documentName: string;
public documentUrl: string;
}
Thank you for the support.