访问 Angular 中的数组元素数组 2
Accessing Array of Array Elements in Angular 2
我有一个数组数组,想使用 *ngFor 一个一个地访问它的所有元素 Example Picture
如果可以提供一些帮助,我可以访问主数组但不能访问数组中的数组元素。
我的输出应该是:
MS、数据 1、日期 2、名称、20、粉红色
我正在努力
<li *ngFor="let l of carels">
<input
type="text"
class="col-sm-6"
value="{{l.name}}">
<input
type="text"
class="col-sm-3"
value="{{l.category}}">
<input
type="date"
class="col-sm-3"
value="{{l.date}}">
</li>
但无法访问内部数组的元素
我的内部数组类型为:
export class SharedPeople {
constructor(public nameIn: string, public age: number) {}
}
您需要另一个 ngFor 来遍历名称
<li *ngFor="let l of carels">
<div *ngFor="let name of l.names">{{ name.nameln + ": " + name.age}} </div>
<input type="text" class="col-sm-3" value="{{l.category}}">
<input type="date" class="col-sm-3" value="{{l.date}}">
</li>
我有一个数组数组,想使用 *ngFor 一个一个地访问它的所有元素 Example Picture
如果可以提供一些帮助,我可以访问主数组但不能访问数组中的数组元素。
我的输出应该是: MS、数据 1、日期 2、名称、20、粉红色
我正在努力
<li *ngFor="let l of carels">
<input
type="text"
class="col-sm-6"
value="{{l.name}}">
<input
type="text"
class="col-sm-3"
value="{{l.category}}">
<input
type="date"
class="col-sm-3"
value="{{l.date}}">
</li>
但无法访问内部数组的元素
我的内部数组类型为:
export class SharedPeople {
constructor(public nameIn: string, public age: number) {}
}
您需要另一个 ngFor 来遍历名称
<li *ngFor="let l of carels">
<div *ngFor="let name of l.names">{{ name.nameln + ": " + name.age}} </div>
<input type="text" class="col-sm-3" value="{{l.category}}">
<input type="date" class="col-sm-3" value="{{l.date}}">
</li>