Error when consuming angular api

0
Good afternoon. I am consuming an api (pokemon), But it does not work,

PokeListenerComponent.html: 6 ERROR Error: Can not find a supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.

My component:

import { HttpClient } from '@angular/common/http';
import { ApiService } from './../api.service';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-poke-listagem',
  templateUrl: './poke-listagem.component.html',
  styleUrls: ['./poke-listagem.component.css']
})

export class PokeListagemComponent implements OnInit {


  pokemon: Array<any>;

  constructor(private apiService: ApiService) { }

  ngOnInit() {
    this.listar();
  }

  listar() {
    this.apiService.listar()
      .subscribe(dados => this.pokemon = dados);
  }

}

My template:

<ul>
<li *ngFor="let p of pokemon" >
  {{p.url}}  {{p.name}}
</li>
</ul>

Service:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class ApiService {


  PokeUrl='http://pokeapi.salestock.net/api/v2/pokemon'; 
  constructor(private http: HttpClient) { }

  listar() { //lista os filmes
    return this.http.get<any[]>('${this.PokeUrl}');
  }



}
    
asked by anonymous 31.05.2018 / 20:23

1 answer

0

Attempts to initialize the variable

pokemon: Pokemon[]= []

or

 pokemon: any[]= []
    
01.06.2018 / 10:28