4

i have one array and i want display array index and it's value also in angular 5 html, here is my array,

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"}

below is my html code,

<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>
1
  • 1
    Please elaborate more so that others can understand and provide the solution that you are expecting. Commented Jan 23, 2018 at 7:17

2 Answers 2

3

Till now the best / shortesr answer I found is

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>

WORKING DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

@Chaudhary, Glad to know , Happy Coding :)
0

You could use filter of Angular

{{ getAttendanceData_new | filter : {'name':index} }}

2 Comments

but i did not get name bcoz my array Index is not an integer it's NAME, so how can i get Name?
it give Error "The pipe 'filter' could not be found"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.