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

34 lines
912 B
TypeScript
Raw Normal View History

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