【发布时间】:2018-11-11 15:05:53
【问题描述】:
我正在尝试动态填充表格,但不知道为什么这不起作用!
在这里我得到了我的 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 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>
但我的表只是呈现这个:
[object Object] [object Object] [object Object] [object Object] [object Object]
【问题讨论】:
-
console.log(customerArray);customerArray在哪里定义?还是应该是this.customerArray?
标签: html-table angular6 ngfor