0

Following is my html code,

            <tr *ngFor="#c of content|async">           
                <td> {{c.name}}</td>
                <td>{{c.skill}}</td>
            </tr>

and in my json,

[{"name":"abc","skill":"xyz"}]

This is working but i need to iterate through this json string as,

var obj = {a: 1, b: 2};
for (var key in obj) {
  if (obj.hasOwnProperty(key)) {
    var val = obj[key];
    console.log(val);
  }
}

this code is in javascript I want to do this in typescript.

1 Answer 1

2

You could create a custom pipe to return the list of key for each element. Something like that:

@Pipe({name: 'keys'})
export class KeysPipe implements PipeTransform {
  transform(value, args:string[]) : any {
    let keys = [];
    for (let key in value) {
      keys.push(key);
    }
    return keys;
  }
}

and use it like that:

<tr *ngFor="#c of content | async">           
  <td *ngFor="#key of c | keys">{{key}}: {{c[key]}}</td>
</tr>
Sign up to request clarification or add additional context in comments.

Comments

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.