Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 230966

[Ionic 3] Empty List with *ngFor and pipe (present data from object) [Solved]

$
0
0

I solved the above error with:

this.myUser = newUser.results;

Results is the name of the called object api (ex. from https://randomuser.me/api/?results=10 ).

Provider - contactos-api.ts

import { Http, Response } from "@angular/http";
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import { Observable } from "rxjs";

@Injectable()
export class ContactosApiProvider {

  constructor(private http: Http) {
  }

  getData(){
    return this.http.get('https://randomuser.me/api/?results=10')
    .map((data: Response) => data.json());
  }

}

home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http } from '@angular/http';
import { Observable } from 'rxjs';
import { ContactosApiProvider} from '../../providers/contactos-api/contactos-api';
import 'rxjs/add/operator/map';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  myUser = [];

  constructor(public navCtrl: NavController, public contactosApiProvider: ContactosApiProvider) {
      contactosApiProvider.getData().subscribe(newUser => {
        this.myUser = newUser.results;
        console.log(this.myUser);
      });
   }
}

Viewing all articles
Browse latest Browse all 230966

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>