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

25 lines
673 B
TypeScript
Raw Normal View History

2023-02-24 14:12:39 +00:00
import { Component, OnInit } from '@angular/core';
2023-02-24 13:54:17 +00:00
import { 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-list-pokemon',
templateUrl: './list-pokemon.component.html',
})
2023-02-24 14:12:39 +00:00
export class ListPokemonComponent implements OnInit {
pokemonList: Pokemon[];
2023-02-24 13:54:17 +00:00
2023-02-24 14:12:39 +00:00
constructor(private router: Router, private pokemonService: PokemonService) {}
ngOnInit() {
this.pokemonService
.getPokemonList()
.subscribe((pokemonList) => (this.pokemonList = pokemonList));
2023-02-24 14:12:39 +00:00
}
2023-02-24 13:54:17 +00:00
goToPokemon(pokemon: Pokemon) {
this.router.navigate(['/pokemon', pokemon.id]);
}
}