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}');
}
}