Fin section 11 : services

This commit is contained in:
2023-02-24 15:12:39 +01:00
parent de6b2a94ed
commit 1fb0c5c2de
4 changed files with 40 additions and 11 deletions

View File

@@ -1,24 +1,25 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { POKEMONS } from '../mock-pokemon-list';
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) {}
constructor(
private route: ActivatedRoute,
private router: Router,
private pokemonService: PokemonService
) {}
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
);
this.pokemon = this.pokemonService.getPokemonById(+pokemonId);
}
}