Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
Angular provider receives JSON but recognizes its content as none

I have two components that depend on a third component function to receive some JSON data. The function that them both use is this:

getAllPosting(before, after) {
    return new Promise((resolve, reject) => {
      console.log("url", environment.apiLogin + this.apiBase + localStorage.getItem('idEmpresa') + '/' + before  + '/' + after)
      this.http.get(environment.apiLogin + this.apiBase + localStorage.getItem('idEmpresa') + '/' + before  + '/' + after, {headers: {Authorization: this.oauthService.authorizationHeader()}})
        .subscribe((result: any) => {
            console.log("provider result", result)
            resolve(result);
          },
          (error) => {
            reject(error);
          });
    });
  }

On the first component, the console.log("provider result", result) statement shows this result:

All the object fields and information is correct.

However, on the second component, the highlighted console.log shows this result: The fields that we need, amountPaid and balance, keep coming as NaN

It's does not seem to be a back-end problem since on the db all the data and the queries return the correct result. There are thousands of users but none of them have this problem, except for this current user.

This error is resulting to no data being show on the table, like:

The fields that should show on the table are the same fields that are coming back as Nan

I've tried requesting the data on different clients but none of them have this problem. It is exclusive of this one user.

Also, when trying to console.log the array using a forEach iteration, the correct information is showing. However, when trying to console.log the whole object, the main fields that we use for the table keep showing as Nan.

result.forEach(element => {
              console.log("foreeach",element.amountPaid)
            });

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If the data that comes back from the http.get call is truly correct, there is a chance that the object that is returned from the service is later manipulated by the code that is triggered after resolve(result) is called.

So when you attempt to view the result object in the console, what you will see is what the result of that manipulation is, not what the object was during the console.log call. This would explain why you are seeing correct values during the foreach prints, as the console is printing number literals - not objects, however they are likely then changed by the code that gets triggered when the promise is resolved.

Hence, I would recommend checking the code that uses the getAllPosting result.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda