23 lines
583 B
TypeScript
23 lines
583 B
TypeScript
|
import { Injectable } from '@angular/core';
|
||
|
import { POKEMONS } from './mock-pokemon-list';
|
||
|
import { Pokemon } from './pokemon';
|
||
|
|
||
|
@Injectable()
|
||
|
export class PokemonService {
|
||
|
getPokemonList(): Pokemon[] {
|
||
|
return POKEMONS;
|
||
|
}
|
||
|
|
||
|
getPokemonById(pokemonId: number): Pokemon | undefined {
|
||
|
return POKEMONS.find((pokemon) => pokemon.id === pokemonId);
|
||
|
}
|
||
|
|
||
|
getPokemonTypeList(): string[] {
|
||
|
const types: Set<string> = new Set();
|
||
|
POKEMONS.forEach((pokemon) => {
|
||
|
pokemon.types.forEach((type) => types.add(type));
|
||
|
});
|
||
|
return Array.from(types.values());
|
||
|
}
|
||
|
}
|