ng-pokemon-app/src/app/pokemon/detail-pokemon/detail-pokemon.component.ts

34 lines
912 B
TypeScript

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