How to display JS objects in view

Asked

Viewed 411 times

0

There’s already a question from our friend Vinicius Scaramel with this problem, however there is no solution, so come on:

I’m bringing an object in shape JSON via http.get in the Ionic, (using Angularjs), but when displaying it on view with {{}} it only displays [object Object], and does not display my object itself... I’m already losing my hair trying to solve. Let’s go to code:

Function of my representative GET

 getChamadoSelecionado(){
    return this.http.get(this.LINK + "/chamadoSelecionado");
  }

my array receiving my object through the GET

ionViewDidLoad() { //funcao que é executada quando abre a view
  console.log('ionViewDidLoad ChamadoPage');
  this.ChamadosProvider.getChamadoSelecionado().subscribe(    // chamando minha funcao que da o GET na minha api, e retorna o objeto
    data => {
      const objeto_retorno = JSON.parse((data as any)._body); // inserindo na variavel os dados que preciso que estão em data._body (convertido em objeto atraves do JSON.parse)
      this.objetoChamadoSelecionado = objeto_retorno;   //atribuindo o objeto ao meu array
      console.log(this.objetoChamadoSelecionado);    
      }, error => {
        console.log(error);
      })
    }

so far everything is going very well, giving a console.log in my variable that received the return of JSON this beautiful: inserir a descrição da imagem aqui

Code of my View

<ion-header>

  <ion-navbar>
    <ion-title>Chamado</ion-title>
  </ion-navbar>

</ion-header>


<ion-content padding >

<div ><p>{{objetoChamadoSelecionado}}</p></div>


</ion-content>

Here is where it should display my object, but it displays only that inserir a descrição da imagem aqui

I tried already

objectChamadoSelected.number

for example, and I can’t get anything... The strangest thing of all is that on another page I have a return of a list of objects using a *ngFor works...

2 answers

0


You yourself answered your question at the end rs, just use *ngFor:

<ion-list>
    <ion-item *ngFor="let item of objetoChamadoSelecionado">
        <div ><p>{{ item.numero }}</p></div>
    </ion-item>
</ion-list>

0

Just like that:

{{ Objectscall | json }}

Browser other questions tagged

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