import {Component, OnInit, ViewChild} from '@angular/core'; import {VehiculeService}…
- User
import {Component, OnInit, ViewChild} from '@angular/core'; import {VehiculeService} from "../services/vehicule.service"; import {ToastrService} from "ngx-toastr"; import {MatSelect} from "@angular/material/select"; import {DriverService} from "../services/driver.service";
@Component({ selector: 'app-vehicle-form', templateUrl: './vehicle-form.component.html', styleUrls: ['./vehicle-form.component.scss'], providers: [], })
export class VehicleFormComponent implements OnInit { submitted: boolean = false; drivers: any; vehicules: any; @ViewChild('select') select!: MatSelect;
ngOnInit(): void { this.getDrivers(); this.getVehicules(); } constructor(public vehiculeService: VehiculeService, private toast: ToastrService, private driverService: DriverService) {}
getDrivers() { this.driverService.getDrivers().subscribe((data: any) => { this.drivers = data; console.log(data); }); }
getVehicules() { this.vehiculeService.getVehicles().subscribe((data: any) => { this.vehicules = data; console.log(data); });
}
onSubmitVehicule() { this.submitted = true; if (this.vehiculeService.vehicleForm.invalid) { return; } if (this.vehiculeService.vehicleForm.value.Id === 0) { this.insertVehicule(); } else { this.vehiculeService.putVehicle(); } }
private insertVehicule() { this.vehiculeService.postVehicle().subscribe( { next: () => { this.toast.success('Véhicule ajouté avec succès'); this.resetForm(); }, error: () => { this.toast.error('Erreur lors de l'ajout du véhicule'); } } ); }
protected resetForm() { this.submitted = false; this.vehiculeService.vehicleForm.reset(); this.vehiculeService.vehicleForm.setValue({ Id: 0, ConsommationMoyenne: 0, DateAchat: '', NumeroAssurance: "", RapportPoidsPuissance: 0, TypeCarburant: "", TypeBoiteVitesse: "", Constructeur: '', Modele: '', NumeroSerie: '', Immatriculation: '', Segment: '', NombrePlaces: 0, Cylindree: 0, Poids: 0, PuissanceMoteur: 0, EmissionCo2: 0, PrixAchat: 0, VignetteCritair: '', ValiditeCritair: '', Achat: true, Location: true, Kilometrage: 0, TypeVehicule: "", DateMiseEnCirculation: '', DateDerniereModification: '', IdConducteur: 0 }); }
ChangeModele() { this.vehiculeService.vehicleForm.controls['Modele'].setValue(''); } }
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.