use*_*088 5 arrays typescript ngfor angular
我需要显示位于对象数组中的数组质量.我试过ngFor使用下面的代码调用它.我的用法有问题ngFor吗?
import { Component} from '@angular/core';
@Component({
selector: 'my-app',
template: `<table>
<thead>
<tr>
<th>Name</th>
<th>Quality1</th>
<th>Quality2</th>
</tr>
</thead>
<tbody>
<tr *ngFor"let item of people">
<td>{{item.Name}}</td>
<td *ngFor"let item of people.quality">item.quality1</td>
<td *ngFor"let item of people.quality">item.quality2/td>
</tr>
</tbody>
</table>
})
export class AppComponent{
people: any = [{Name:"John", quality:[{quality1: "nice", quality2: "humble"}]}, {Name:"Dave", quality:[{quality1: "kind", quality2: "caring"}]} ];
}
Run Code Online (Sandbox Code Playgroud)
截至目前,只有名字出现在表格中,但我也希望质量出现.
您可以使用<ng-container>来组合多个节点,而*ngFor无需向 DOM 引入另一个元素:
<ng-container *ngFor"let item of people.quality">
<td>item.quality1</td>
<td>item.quality2/td>
</ng-container>
Run Code Online (Sandbox Code Playgroud)