I'm currently working on parsing retrieved data from Firebase within an Angular (Typescript) project.
The structure of my JSON data in Firebase resembles the following:
"customer" : {
"customerId1" : {
"documents" : {
"documentId1" : {
"documentName" : "file1.pdf",
"documentUrl" : "someUrl1"
},
"documentId2" : {
"documentName" : "file2.pdf",
"documentUrl" : "someUrl2"
}
},
"email" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8deef8fef9e2e0e8f9bccde8e0ece4e1a3eee2e0">[email protected]</a>",
"name" : "Customer 1",
},
"customerId2" : {
"documents" : {
"documentId3" : {
"documentName" : "file3.pdf",
"documentUrl" : "someUrl3"
},
"documentId4" : {
"documentName" : "file4.pdf",
"documentUrl" : "someUrl4"
}
},
"email" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="83e0f6f0f7eceee6f1b1c3e6eee2eaefade0ecee">[email protected]</a>",
"name" : "Customer 2",
}
}
Each customer entry includes three main properties at the first level: documents, email, and name. The documents property further contains nested properties such as documentName and documentUrl. To parse this customer data, I have implemented the following code snippet.
customer.component.ts:
...
export class CustomerComponent implements OnInit {
customerObservable: Observable<any[]>;
customerList: Customer[];
constructor(db: AngularFireDatabase) {
// Listening to customer data
this.customerObservable.subscribe(data => {
this.customerList = data;
});
}
}
...
This code allows me to retrieve and loop through the data using the ngFor directive in HTML with the help of the customerList variable. Now, my question is how can I accomplish something like the following?
// Variable containing an array of arrays representing customers' document collections
documentList: Document[][];
// Alternatively,
// Variable storing individual customer documents
customerDocuments: Document[];
// Here's what the Document model entails
export class Document {
public documentName: string;
public documentUrl: string;
}
Thank you for your assistance.