Angular 6 - 动态填充 table

Angular 6 - Populate table dynamically

我正在尝试动态填充 table,但无法弄清楚为什么这不起作用!

在这里我得到了我的 json,我将对象数组保存在 customerArray 中。

export class AllCustomersComponent implements OnInit {
customerArray: any;


    constructor(private http : HttpClient ) {}

    ngOnInit() {
         this.http.get('http://www.mocky.io/v2/5be715ce2e00008a0016945e')
        .subscribe((data) => {
           this.customerArray = data;
          console.log(customerArray);
      }
    }
}

这里我试图用上述数组填充 table。

<table class="table">
        <thead>
          <tr>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Age</th>
            <th scope="col">Edit</th>
            <th scope="col">Delete</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Mark</td>
            <td>Otto</td>
            <td>46</td>
            <td><i class="fas fa-edit"></i></td>
            <td><i class="fas fa-trash-alt"></i></td>
          </tr>
          <tr>
            <td *ngFor="let customer of customerArray">{{customer}}</td>
          </tr>
        </tbody>
      </table>

但是我的 table 只是渲染这个:

[object Object] [object Object] [object Object] [object Object] [object Object]

您的客户是一个对象,angular 应该如何知道要为它呈现什么?

你可能需要的是这样的:

<tr *ngFor="let customer of customerArray">
   <td>{{customer.firstname}}</td>
   <td>{{customer.lastname}}</td>
   <td>{{customer.age}}</td>
   <td>{{customer.whatever}}</td>
   <td>{{customer.whatever}}</td>
</tr>