Fin module 10 : routes et modules

This commit is contained in:
2023-02-24 14:54:17 +01:00
parent a876a3e70b
commit de6b2a94ed
15 changed files with 197 additions and 56 deletions

View File

@@ -0,0 +1,56 @@
<div *ngIf="pokemon" class="row">
<div class="col s12 m8 offset-m2">
<h2 class="header center">{{ pokemon.name }}</h2>
<div class="card horizontal hoverable">
<div class="card-image">
<img [src]="pokemon.picture" />
</div>
<div class="card-stacked">
<div class="card-content">
<table class="bordered striped">
<tbody>
<tr>
<td>Nom</td>
<td>
<strong>{{ pokemon.name }}</strong>
</td>
</tr>
<tr>
<td>Points de vie</td>
<td>
<strong>{{ pokemon.hp }}</strong>
</td>
</tr>
<tr>
<td>Dégâts</td>
<td>
<strong>{{ pokemon.cp }}</strong>
</td>
</tr>
<tr>
<td>Types</td>
<td>
<span
*ngFor="let type of pokemon.types"
class="{{ type | pokemonTypeColor }}"
>{{ type }}</span
>
</td>
</tr>
<tr>
<td>Date de création</td>
<td>
<em>{{ pokemon.created | date : "yyyy-MM-dd" }}</em>
</td>
</tr>
</tbody>
</table>
</div>
<div class="card-action">
<a (click)="goToPokemonList()">Retour</a>
</div>
</div>
</div>
</div>
</div>
<h4 *ngIf="!pokemon" class="center">Aucun pokémon à afficher !</h4>

View File

@@ -0,0 +1,28 @@
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']);
}
}