Change value from back to front end (in service)

Asked

Viewed 50 times

-1

I am receiving a distinct back object (normally I have a back pattern) because of that the values of id came divergent than I need, I would change them in the service to fit on my front but do not know how to do it.

for example I hope an object with id and value the back this returning me code and value

follows what I tried to do

Ajuste(model: any): PessoaFisica {
  if (!model) {
    return model;
  }

  return {
    ...model,
idade && idade.codigo{idade.id}

}

but it didn’t work

I hope you can understand

  • I didn’t really understand no, what do you mean "I’m getting a distinct back object"?

  • I usually consult a back and everything comes cute, but this particular data then vindk from another system, I can not change back, because it is already being used

  • Good if I understand enough in your model (I believe there is one) in Angular, add the properties that are missing and use them.

1 answer

0


Are you using the HttpClient? If yes, you can use the Operator map Rxjs to change type, so:

this.objetoConvertido = this.httpClient.get<ObjetoIdValue>('suapibackend').pipe(map(resposta =>{
  const conversion = {id: resposta.codigo, value: resposta.valor}
  return conversion;
}));

Browser other questions tagged

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