title: Render a map object (with dynamic keys and values) into angular mat-table (columns and rows as keys and values of the map)
body: <p>I am developing a POC using angular8 as frontend and SpringBoot as backend. My backend function returns me a List of Map objects (<code>List &lt; Map &lt; String, Object > ></code>) which has dynamic keys and values.
  I need to use this map array in frontend angular using mat-table inside mat-dialog-content. I'm stuck on defining the keys and values as the required attributes for the mat table. Please help me in populating the dynamic list of map objects (column headers as map key, and row as map value).</p>
  
  <p>Posted my component and html files below:</p>
  
  <p>component:</p>
  
  <pre class="lang-js prettyprint-override"><code>export class ProfileDialogComponent {
    username: String = "";
    mapArray: Map &lt; String, Object &gt; [] = [];
    constructor(private dialogRef: MatDialogRef &lt; ProfileDialogComponent &gt; ,
      @Inject(MAT_DIALOG_DATA) data, private userService: UserService) {
      this.username = data.username;
      this.userService.getImportedUserCareer(this.username).subscribe(data =&gt; {
        this.mapArray = data;
      });
    }
  }
  </code></pre>
  
  
  
  <p>html:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div&gt;
    &lt;mat-dialog-content *ngFor="let map of mapArray"&gt;
      &lt;mat-table class="mat-elevation-z8" [dataSource]="map"&gt;
  
        &lt;ng-container matColumnDef="column" *ngFor="let column of map | keyvalue"&gt;
          &lt;mat-header-cell *matHeaderCellDef&gt;{{column}}&lt;/mat-header-cell&gt;
          &lt;mat-cell *matCellDef="let element"&gt;{{element[column]}}&lt;/mat-cell&gt;
        &lt;/ng-container&gt;
        &lt;mat-header-row *matHeaderRowDef="map"&gt;&lt;/mat-header-row&gt;
        &lt;mat-row *matRowDef="let row; columns: map"&gt;&lt;/mat-row&gt;
      &lt;/mat-table&gt;
    &lt;/mat-dialog-content&gt;
  &lt;/div&gt;
  </code></pre>
  
  
  
  <p>At this point I'm getting the following error:
      Error: Duplicate column definition name provided: "column".</p>
  
  <p>I have the map array populated in my component with map of string and string values. But the implementation logic in html is not complete, it would be really helpful if somebody can guide me how to populate the map data in mat table.</p>
  
  <p>PS: I have iterated the map array in mat-dialog-content so that I get each map object in mat-table, so that the map keys and values should be populated as each mat-table column headers and rows inside each mat-dialog-content.</p>
  
  <p>Below is a sample of the data</p>
  
  <pre><code>[
    {
      "Test Matches": 320,
      "Runs": 17500,
      "High Score": 242,
      "Batting Avg": 65.42,
      "Wickets": 14,
      "Bowling Avg": 31.76,
      "Best Bowling": "1/34",
      "Catches": 173,
      "MoS": 25
    },
    {
      "ODI Matches": 150,
      "Runs": 15750,
      "High Score": 184,
      "Batting Avg": 62.75,
      "Catches": 173,
      "MoM": 54
    }
  ]
  </code></pre>
  
  <p>Please help!</p>
  
  <p>Thanks,
  Shihad</p>