URL details isa + romain

This commit is contained in:
HarmandI 2022-01-17 21:02:22 +01:00
parent 4fbea6ac18
commit 0936d942e0
2 changed files with 28 additions and 6 deletions

View File

@ -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)

View File

@ -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);
}
}