0

This is the format of data I am getting. How can I display all key names (i.e key1, key2, key3...) and also the subkeys (i.e subkey1_1, subkey1_2...) and their values?

Array_main=[
            {"key1":[
                      {"subkey1_1":
                        {"key1":"value1","key2":"value2"}
                      },
                      {"subkey1_2":                                                   {"ky1":"value1","ky2":"value2"}
                      },
                     ]
             },
             {"key2":[
                      {"subkey2_1":
                        {"key1":"value1","key2":"value2"}
                      },
                      {"subkey2_2":                                                   {"key1":"value1","key2":"value2"}
                      },
                     ]
             ]},
             {"key3":[]},
              ......
              
              ];

If I use something like:

 <ion-list>  
      <ion-card *ngFor = "let array of array_main">        
  <ion-item>        
    <h2 >{{ array}}</h2>       
  </ion-item>

But I am getting [object Object] in the HTML view. How do I parse to inner objects and display their keys and values in ionic2?

I used pipe , but it is displaying keys as numbers instead i want them to display as key names...

import { Pipe, PipeTransform} from '@angular/core';

@Pipe({
  name: 'pipe'
})


export class ObjectValuesPipe implements PipeTransform {
  transform(obj: any) {
 
    let result = [];
    for (var key in obj) {
      if (obj.hasOwnProperty(key)) {

        result.push(key);
       
      }
    }
    return result;
  }
}
<ion-list>  
      <ion-card *ngFor = "let array of array_main | pipe">        
  <ion-item>        
    <h2 >{{ array}}</h2>       
  </ion-item>

The ouput is 0 , 1,2 ... instead i want it to be like .."key1","key2"...

Lisa
  • 655
  • 3
  • 10
  • 34
  • http://stackoverflow.com/questions/37431578/iteration-a-json-object-on-ngfor-in-angular-2 – Suraj Rao Mar 06 '17 at 13:58
  • Possible duplicate of [iteration a json object on Ngfor in angular 2](http://stackoverflow.com/questions/37431578/iteration-a-json-object-on-ngfor-in-angular-2) – Nico Mar 07 '17 at 09:17

0 Answers0