Iterate a Json Object with ngFor

前端 未结 1 1986
执念已碎
执念已碎 2020-11-28 16:56

I get from a webserver the following JSON String.

[
{\"name\":\"Joe Lincoln\",\"age\":\"42\",\"grade\":\"9\",\"active\":\"1\"},
{\"name\":\"Jack Smith\",\"ag         


        
相关标签:
1条回答
  • 2020-11-28 17:05

    You can get the keys from an object using Object.keys (requires polyfill in IE AFAIK)

    import { Pipe, PipeTransform } from '@angular/core';
    @Pipe({ name: 'keys' })
    export class KeysPipe implements PipeTransform {
      transform(value): any {
        if(!value) return null;
        return Object.keys(value);
      }
    }
    
    <div *ngFor="let key of member | keys">{{member[key]}}</div>
    

    For Angular 6 see How to iterate object keys using *ngFor

    0 讨论(0)
提交回复
热议问题