0
dataset: any = {
    "days": [
      {
        "datevalue":1,
        "status":"disable",
        "addclass":"notallowed",
        "avability":[]
      },
      {
        "datevalue":2,
        "status":"disable",
        "addclass":"allowed",
        "avability":[]
      }
    ]
}



<tr *ngFor="let row of dataset.days; let i = index">
   <td *ngFor="let day of row | keyvalue">
      {{day.datevalue}}
    </td>
</tr>

How to print the datevalue inside td ? Currently its showing blank.

I AM STUCK VERY BADLY. PLEASE HELP

1

2 Answers 2

3

row is an object, and you re trying to loop it, it's not possible, you need to use Object.keys: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

for (let row of this.dataset.days) {
  for (let data of Object.keys(row)) {
    console.log(row[data]);
  }
 }

EDIT: To loop an object through a *ngFor, there is a pipe KeyValuePipe: https://angular.io/api/common/KeyValuePipe

<div *ngFor="let item of yourObject | keyvalue">
  {{item.key}}:{{item.value}}
</div>

in your case :

    <tr *ngFor="let row of dataset.days; let i = index"> 
       <td *ngFor="let item of row | keyvalue"> 
           {{ item.value }} 
       </td> 
    </tr>
Sign up to request clarification or add additional context in comments.

6 Comments

You might want to link to the English version of the documentation for this English oriented site.
Yes, i didn't pay attention, edited
How to show in view file? <tr *ngFor="let row of dataset.days; let i = index"> <td *ngFor="let data of row"> {{data}} </td> </tr>
I edited, my answer
@Soukyone how to print datevalue in td?
|
0

While this.dataset.days is an array (the outer for ... of loop doesn't throw an error), its elements are objects, and you can't iterate through them.

for (let row of this.dataset.days) {
  console.log(row);
}

Will work.

1 Comment

<tr *ngFor="let row of dataset.days; let i = index"> <td *ngFor="let data of row"> {{data}} </td> </tr>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.