Separate Array within Object

Asked

Viewed 360 times

0

I have an array inside an object, I would like to know how to separate the items service_name and service_value. I don’t know if there’s a way to do this in html itself...

pedido{id_pedido:"17",
id_usuario:"34",
nome_servico:"Servico 01,Servico 02,Servico 03"
valor_servico:"250,200,380",
total_servico:"830"}
<div *ngFor="let item of pedido">    
  <div>{{item.nome_servico}}</div>
  <div>{{item.valor_servico}}</div>
</div>

  • In this case just call in the HTML itself: pedido.nome_servico.

  • Won’t work the for since the object has only one group of values.

  • @Diegosouza, the problem is that in html everything comes together 250,200,380

  • Ahhh. But where do these values come from?

  • as well as an object as shown there...

  • So, but it would be interesting to come from the right bank already for you to use in for as an object. So you would have a lot of work.

  • I know, but then I get into a saving problem, which I already did, so I’m trying this way...

  • And how you wanted to show this data?

  • Separate, type like this:

  • Servico 01 - 200 Servico 02 - 250 Servico 03 - 380

Show 5 more comments

1 answer

2

pedido = {
  id_pedido: "17",
  id_usuario: "34",
  nome_servico: "Servico 01,Servico 02,Servico 03",
  valor_servico: "250,200,380",
  total_servico: "830"
};

let arrSer = pedido.nome_servico.split(',');
let arrVal = pedido.valor_servico.split(',');

pedido.nome_servico = arrSer;
pedido.valor_servico = arrVal;

HTML

<div *ngFor="let item of pedido.nome_servico; let i = index" [attr.data-index]="i">    
  <div>{{item}} - {{pedido.valor_servico[i]}}</div>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.