Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. <div [formArrayName]="doc.typeSelector">
  2. {{ doc.typeSelector }}
  3. </div>
  4. <div *ngIf="documents[doc.typeSelector]">
  5. <mat-table
  6. [dataSource]="documents[doc.typeSelector]"
  7. *ngFor="let col of docColumns">
  8. <ng-container [matColumnDef]="col">
  9. <th mat-header-cell *matHeaderCellDef> {{ col | uppercase }} </th>
  10. <td mat-cell *matCellDef="let element"> {{ element[col] }} </td>
  11. </ng-container>
  12. <tr mat-header-row *matHeaderRowDef="docColumns"></tr>
  13. <tr mat-row *matRowDef="let row; columns: docColumns;"></tr>
  14. </mat-table>
  15. </div>
  16.  
  17. documents: object = {};
  18. docColumns: string[] = ["name", "uploadDate", "uri", "comments"];
  19. docs = [];
  20. docForm: FormGroup;
  21. docTypes: object = {
  22. fs: 'Financial Statements',
  23. id: 'Identity Document',
  24. ad: 'Bank Account Details',
  25. cd: 'Constitutional Document',
  26. pd: 'Power Document',
  27. };
  28.  
  29. [...] this.docForm = this.fb.group({});
  30. Object.keys(this.docTypes).map(
  31. type => {
  32. this.docForm.addControl(type, this.fb.array([]));
  33. this.docs.push({
  34. typeName: this.docTypes[type],
  35. typeSelector: type
  36. });
  37. }
  38. );
  39.  
  40. // Info for the docForm:
  41. const cusDocs = this.customer.docRefs;
  42. Object.keys(cusDocs).map(docType => {
  43. const currDocs = [];
  44. cusDocs[docType].forEach(doc => {
  45. currDocs.push(this.customerService.createNewDoc(doc));
  46. });
  47. const matchForm = this.docForm.get(docType) as FormArray;
  48. currDocs.forEach(form => {
  49. matchForm.push(form);
  50. });
  51. });
  52. Object.keys(this.docForm.value).map(docType => {
  53. const currForm = this.docForm.get(docType) as FormArray;
  54. if (currForm.value.length > 0) {
  55. Object.keys(currForm.value).map(doc => {
  56. const currentDoc = currForm.at(+doc).value;
  57. const newDocRow = {
  58. name: currentDoc.name,
  59. uploadDate: currentDoc.uploadDate,
  60. uri: currentDoc.uri,
  61. comments: currentDoc.comment
  62. };
  63. if (!this.documents[docType]) {
  64. this.documents[docType] = [];
  65. }
  66. this.documents[docType].push(newDocRow);
  67. console.log(this.documents[docType]);
  68. });
  69. }
  70. });
  71. console.log(this.documents);
  72. console.log(this.docColumns);
  73.  
  74. <div *ngIf="documents[doc.typeSelector]">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement