import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { POKEMONS } from '../mock-pokemon-list'; import { Pokemon } from '../pokemon'; @Component({ selector: 'app-detail-pokemon', templateUrl: './detail-pokemon.component.html', }) export class DetailPokemonComponent implements OnInit { constructor(private route: ActivatedRoute, private router: Router) {} pokemonList: Pokemon[]; pokemon: Pokemon | undefined; ngOnInit(): void { this.pokemonList = POKEMONS; const pokemonId: string | null = this.route.snapshot.paramMap.get('id'); if (pokemonId) { this.pokemon = this.pokemonList.find( (pokemon) => pokemon.id === +pokemonId ); } } goToPokemonList() { this.router.navigate(['/pokemons']); } }