Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
Ionic 2 Variable isn't showing in view

I'm having some trouble with Angular 2(I'm new at it). My Ionic app doesn't recognize my array. Whenever I try to access the properties from may arry or object, ionic 2 says that my variable is empty. This is my code: enter image description here My "view":

And this is my controller showItem.ts:

enter image description here

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Try giving your book type of any see if your data get assigned to book first:

book: any = [];

Also when you pushing data into book, try using this.book instead of passing the this into the function.

this.book.push({id:obj.id, title: obj.title, imagem: obj.imagem});
over 4 years ago · Santiago Trujillo Report

0

The problem was into my provider. Actually, it's kinda of a bug that I have to cast into just one object. My json was returning a Object Inside a object. I solved this problem by casting my res.json() into my object name: "book". Like this: res.json()['book']


    buscarLivro(id)
    {
      if (this.dataBook) 
      {
        return Promise.resolve(this.dataBook);
      }
      // Dont have the data yet
      return new Promise(resolve => {
        this.http.get('http://localhost:8000/api/books/'+id)
          .map(res => res.json()['book'])
          .subscribe((data: any) => {
            this.dataBook = data;
            resolve( this.dataBook);
          });
      });
    }

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!