From 0936d942e08824bc0511089df24f70620e937f01 Mon Sep 17 00:00:00 2001 From: HarmandI Date: Mon, 17 Jan 2022 21:02:22 +0100 Subject: [PATCH] URL details isa + romain --- src/app/app-routing.module.ts | 2 +- .../page-details/page-details.component.ts | 32 ++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 35f292d..d53e7f9 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -11,7 +11,7 @@ const routes: Routes = [ { path: '', redirectTo: 'home', pathMatch: 'full' }, { path: 'home', component: PageAccueilComponent }, - { path: 'details/:productId', component: CardPlanteComponent }, + { path: 'details/:productId', component: PageDetailsComponent}, {path : 'account', loadChildren : () => import('./modules/account/account.module') .then(m => m.AccountModule) diff --git a/src/app/pages/page-details/page-details.component.ts b/src/app/pages/page-details/page-details.component.ts index d36aa60..28fd5e1 100644 --- a/src/app/pages/page-details/page-details.component.ts +++ b/src/app/pages/page-details/page-details.component.ts @@ -1,4 +1,6 @@ import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { PlantouneService } from 'src/app/services/plantoune.service'; @Component({ @@ -8,15 +10,35 @@ import { Component, OnInit } from '@angular/core'; }) export class PageDetailsComponent implements OnInit { - detailsPlant: any - constructor() { + product : any; + public listData : any[]; + + constructor(private route: ActivatedRoute, private plantouneService: PlantouneService) { + + this.listData = []; } ngOnInit(): void { - } + this.plantouneService.getData().subscribe( + (listPlant: any[]) => { + console.log(listPlant); - test(texte:any){ - console.log(texte); + this.listData = listPlant; + + + //ajoute le ProductId à l'url + const routeParams = this.route.snapshot.paramMap; + const productIdFromRoute = Number (routeParams.get('productId')); + + //trouve le produit qui correspond à l'Id de la route + + this.product = this.listData.find (product => product.product_id === productIdFromRoute); + + }) +} + + test(id:any){ + console.log(id); } }