如何获取 angular 5 html 中的数组索引?
how to get array index in angular 5 html?
我有一个数组,我想显示数组索引,它的值也在 angular 5 html,这是我的数组,
Anil K Chaudhary
0: {is_present: "1", name: "Anil K Chaudhary", date: "22"}
1: {is_present: "0", name: "Anil K Chaudhary", date: "20"}
Laxman J chavda
0: {is_present: "0", name: "Laxman J chavda", date: "22"}
1: {is_present: "1", name: "Laxman J chavda", date: "20"}
下面是我的 html 代码,
<tr *ngFor = "let getAttendanceData_new of getAttendanceData[key]">
<td>{{getAttendanceData_new}}</td> // i want to display array Index here. (e.g "Anil K Chaudhary", "Laxman J Chavda")
<!-- ======== AND ALSO WANT HERE THEIR VALUE ======== -->
<td *ngFor="let getDays_new of getDays;let i = index">
<b *ngIf="getAttendanceData.is_present == 1 && getDays_new == getAttendanceData.date" style="color:green">P</b>
<b *ngIf="getAttendanceData.is_present == 0 && getDays_new == getAttendanceData.date" style="color:lightgrey">A</b>
</td>
</tr>
您可以使用 filter
个 Angular
{{ getAttendanceData_new | filter : {'name':index} }}
到目前为止,我找到的最佳/最短答案是
Component side :
objectKeys = Object.keys;
Template side :
<div *ngFor='let key of objectKeys(jsonObj)'>
Key: {{key}}
<div *ngFor='let obj of jsonObj[key]'>
{{ obj.title }}
{{ obj.desc }}
</div>
</div>
我有一个数组,我想显示数组索引,它的值也在 angular 5 html,这是我的数组,
Anil K Chaudhary
0: {is_present: "1", name: "Anil K Chaudhary", date: "22"}
1: {is_present: "0", name: "Anil K Chaudhary", date: "20"}
Laxman J chavda
0: {is_present: "0", name: "Laxman J chavda", date: "22"}
1: {is_present: "1", name: "Laxman J chavda", date: "20"}
下面是我的 html 代码,
<tr *ngFor = "let getAttendanceData_new of getAttendanceData[key]">
<td>{{getAttendanceData_new}}</td> // i want to display array Index here. (e.g "Anil K Chaudhary", "Laxman J Chavda")
<!-- ======== AND ALSO WANT HERE THEIR VALUE ======== -->
<td *ngFor="let getDays_new of getDays;let i = index">
<b *ngIf="getAttendanceData.is_present == 1 && getDays_new == getAttendanceData.date" style="color:green">P</b>
<b *ngIf="getAttendanceData.is_present == 0 && getDays_new == getAttendanceData.date" style="color:lightgrey">A</b>
</td>
</tr>
您可以使用 filter
个 Angular
{{ getAttendanceData_new | filter : {'name':index} }}
到目前为止,我找到的最佳/最短答案是
Component side :
objectKeys = Object.keys;
Template side :
<div *ngFor='let key of objectKeys(jsonObj)'>
Key: {{key}}
<div *ngFor='let obj of jsonObj[key]'>
{{ obj.title }}
{{ obj.desc }}
</div>
</div>