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); }); }
onConstructeurChange() { this.filteredModels = this.vehicules.filter((x: any) => x.Constructeur === this.vehiculeService.vehicleForm.value.Constructeur).map((x: any) => x.Modele); }
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 }); }
}
- Assistant
- User
ok and next
- Assistant
- User
adapte mon code : Constructeur <select (selectionchange)="onConstructeurChange()" id="constructeur" name="constructeur" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" formControlName="Constructeur" > <option *ngFor="let vehicule of vehicules " [value]="vehicule.Id">{{ vehicule.Constructeur }} <small class="text-red-600 mt-1" *ngIf="vehiculeService.vehicleForm.get('Constructeur')?.hasError('required') && (vehiculeService.vehicleForm.get('Constructeur')?.dirty || vehiculeService.vehicleForm.get('Constructeur')?.touched)"> This field is required.
<div class="sm:col-span-1"> <div class="mb-2 block"> <label for="model" class="font-medium mb-1">Modèle</label> <select id="model" name="model" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" formControlName="Modele"> <option *ngFor="let vehicule of vehicules " [value]="vehicule.Id">{{ vehicule.Modele }}</option> </select> <small class="text-red-600 mt-1" *ngIf="vehiculeService.vehicleForm.get('Modele')?.hasError('required') && (vehiculeService.vehicleForm.get('Modele')?.dirty || vehiculeService.vehicleForm.get('Modele')?.touched)"> This field is required. </small> </div> </div> - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.