erreur
This commit is contained in:
parent
1b18f648a0
commit
be9e510a94
|
@ -1,5 +1,5 @@
|
|||
<div class="form-plant">
|
||||
<form [formGroup]="plantForm">
|
||||
<form [formGroup]="plantForm"(ngSubmit)="onSubmit()">
|
||||
<div class="form-floating">
|
||||
<input
|
||||
type="text"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
|
||||
import { Plant } from '../../models/plant';
|
||||
import { AdminService } from '../../services/admin.service';
|
||||
|
@ -13,6 +13,7 @@ export class FormulaireComponent implements OnInit {
|
|||
|
||||
@Input() plantInfos!: Plant;
|
||||
@Input()buttonLabel!:String;
|
||||
@Output()submitted= new EventEmitter<Plant>();
|
||||
constructor(private fb : FormBuilder, private adminService: AdminService) {
|
||||
|
||||
}
|
||||
|
@ -28,10 +29,12 @@ export class FormulaireComponent implements OnInit {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
addPlant(){}
|
||||
|
||||
updatePlant(){}
|
||||
public onSubmit(): void {
|
||||
this.submitted.emit(this.plantForm.value);
|
||||
}
|
||||
}
|
||||
|
||||
function newEventEmitter() {
|
||||
throw new Error('Function not implemented.');
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
<h1>Ajouter une plante</h1>
|
||||
<app-formulaire [buttonLabel]="'Ajouter une plante'"></app-formulaire>
|
||||
<app-formulaire (submitted)="onSubmitted($event)" [buttonLabel]="'Ajouter une plante'"></app-formulaire>
|
||||
|
|
|
@ -21,6 +21,7 @@ import { AdminService } from '../../services/admin.service';
|
|||
export class PageAjouterComponent implements OnInit {
|
||||
public plantForm: FormGroup;
|
||||
public isAdd: boolean = false;
|
||||
public newplant = new Plant();
|
||||
|
||||
|
||||
constructor(private fb: FormBuilder, private router: Router, private adminService: AdminService) {
|
||||
|
@ -32,7 +33,7 @@ export class PageAjouterComponent implements OnInit {
|
|||
|
||||
}
|
||||
|
||||
public onSubmit(): void {
|
||||
public onSubmitted(submittedPlant: Plant): void {
|
||||
const nameValue = this.plantForm.value['nameFC'];
|
||||
const priceValue = this.plantForm.value['priceFc'];
|
||||
const quantityValue = this.plantForm.value['quantityFc'];
|
||||
|
@ -43,18 +44,18 @@ export class PageAjouterComponent implements OnInit {
|
|||
const idValue = this.plantForm.value[''];
|
||||
|
||||
const plant : Plant = {
|
||||
name: nameValue,
|
||||
price: priceValue,
|
||||
quantity: quantityValue,
|
||||
inStock: [inStockValue],
|
||||
category: [categoryValue],
|
||||
urlPicture: 'https//picsum.photos/id/18/200/300',
|
||||
rating: ratingValue,
|
||||
product_name: nameValue,
|
||||
product_price: priceValue,
|
||||
product_qty: quantityValue,
|
||||
product_instock: [inStockValue],
|
||||
product_breadcrumb_label: [categoryValue],
|
||||
product_url_picture: 'https//picsum.photos/id/18/200/300',
|
||||
product_rating: ratingValue,
|
||||
id: idValue,
|
||||
};
|
||||
console.log("coco",plant);
|
||||
|
||||
this.adminService.addPlant(plant)?.subscribe((resp)=>{
|
||||
this.adminService.addPlant(submittedPlant)?.subscribe((resp)=>{
|
||||
})
|
||||
this.router.navigate(['admin']);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ export class AdminService {
|
|||
}
|
||||
|
||||
addPlant(plant: Plant): Observable<any> | void {
|
||||
return this.httpClient.post(`${this.apiUrl}`, plant);
|
||||
return this.httpClient.post(`${this.apiUrl}/list_products`, plant);
|
||||
}
|
||||
onClickDelete(id: number): Observable<any> {
|
||||
return this.httpClient.delete<any>(`${this.apiUrl}/list_products/${id}`).pipe(
|
||||
|
|
Loading…
Reference in New Issue