你好,我对这件事有点陌生,我正在做一个来自pokemon API的get,这是我正在使用的API URL。
这是我的代码
import { Component, OnInit } from '@angular/core';
import { Pokemon, Pokemon2 } from 'src/app/classes/pokemon';
import { PokemonService } from 'src/app/services/pokemon.service';
@Component({
selector: 'app-table',
templateUrl: './table.component.html',
styleUrls: ['./table.component.css']
})
export class TableComponent implements OnInit {
pokemon:any[] = []
constructor(private pokemonservice: PokemonService) { }
ngOnInit(): void {
this.pokemonservice.getPokemon().subscribe((data:any)=>{
this.pokemon= data
console.log(this.pokemon)
})
}
}我有一个只返回http的服务,问题是我的页面上写着OBJECT OBJECT,我知道数据就像
"count": 1126,
"next": "https://pokeapi.co/api/v2/pokemon/?offset=20&limit=20",
"previous": null,
"results": [
{
"name": "bulbasaur",
"url": "https://pokeapi.co/api/v2/pokemon/1/"
}我通常只有一个对象的数据,但这里也写着COUNT,NEXT,PREVIOUS,我怎么处理这个?
发布于 2022-03-02 13:07:12
没有pokemon.name,pokemon.results是对象对象。
试试这个:{{ pokemon.results.name }}。它会给你第一个口袋妖怪的名字。如果您想列出所有口袋妖怪的名称,您可以这样做:
<div *ngFor="let pokemon of pokemon.results">
{{ pokemon.name }}
</div>https://stackoverflow.com/questions/71321888
复制相似问题