print attributes values from JSON array in Angular2

后端 未结 2 1810
我在风中等你
我在风中等你 2021-01-27 23:51

I\'m using Angular2 and I have retrieved some data from Firebase in this way:

dataset: any;
onGetData() {
    this._dataService.getAllData()
        .subscribe(
         


        
2条回答
  •  别那么骄傲
    2021-01-28 00:30

    You can only iterate over an array using ngFor. In your case you need to implement a custom pipe to iterate over keys of an object.

    Something like that:

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

    and use it like that:

               
      Title: {{entry.value.title}}
    
    

    See this question for more details:

    • How to display json object using *ngFor

提交回复
热议问题