Home > Net >  How to biding object of object in angular?
How to biding object of object in angular?

Time:01-29

I have this object:

    data = {
      campaign: {
        testeA: 1,
        testeB: 2,
        testeC: 3
      }
       category{
        categoryA: 15
       }
      ...
     }

I want to bind it on my template, so I tried using keyValuePipe

<p *ngFor= "let item of data| keyvalue"> {{item.key}}</p>

It's working and is showing the text campaign and category, but I need to show the results too How can I do it?

CodePudding user response:

you have to use the name of the variables to bind it to render it, like:

<p *ngFor= "let item of dados"> 
{{item.campaign.testeA}}
{{item.campaign.testeB}}
{{item.campaign.testeC}}
{{item.category.categoryA}}
</p>

Considering that dados is related to data and it's a list of this object

CodePudding user response:

You will probably need to add a second *ngFor statement to get the results e.g.:

<p *ngFor= "let item of data| keyvalue"> 
    <span *ngFor="let i of item | keyvalue">
      {{i.key}}
    </span>
</p>
  •  Tags:  
  • Related