Iterate through json string in Observable angular js 2

后端 未结 1 1069
北荒
北荒 2021-01-26 10:57

Following is my html code,

                       
                 {{c.name}}
                <         


        
相关标签:
1条回答
  • 2021-01-26 11:27

    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>
    
    0 讨论(0)
提交回复
热议问题