Bonjour,
j'ai un soucis au niveau de la construction de ma fonction promise. Je récupère uniquement la première valuer modelCar et impossible de récupérer les autres.
J'ai bien tester mon fichier back dans postman et celui-ci marche sans problème.
Voici le résultat de POSTMAN
J'aimerai donc récupérer les six valeurs qui sont non null.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 { "idCar": null, "idCustomer": null, "licensePlateCar": "DS486PP", "brandCar": "AUDI", "modelCar": "A1", "dateOfCirculationCar": "23/06/2015", "motorizationCar": "90", "colorCar": "NOIR", "versionCar": "1.4 TDI", "urlGrayCard": null }
Voici le code de mon service
et celui de mon component
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 addSIV(siv: Siv): Promise<any> { let promise = new Promise((resolve, reject) => { return this.httpClient.post(`${this.api}/collectCarData.php`, siv).pipe(map( (reponse: any) => { // this.modelCar = reponse.modelCar; // localStorage.setItem('modelCar', JSON.stringify(this.modelCar)); this.brandCar = reponse.brandCar; localStorage.setItem('brandCar', JSON.stringify(this.brandCar)); this.colorCar = reponse.colorCar; localStorage.setItem('colorCar', JSON.stringify(this.colorCar)); this.versionCar = reponse.versionCar; localStorage.setItem('versionCar', JSON.stringify(this.versionCar)); this.dateOfCirculationCar = reponse.dateOfCirculationCar; localStorage.setItem('dateOfCirculationCar', JSON.stringify(this.dateOfCirculationCar)); this.motorizationCar = reponse.motorizationCar; localStorage.setItem('motorizationCar', JSON.stringify(this.motorizationCar)); }, resolve({modelCar: this.modelCar, brandCar: this.brandCar, colorCar: this.colorCar, versionCar: this.versionCar, dateOfCirculationCar: this.dateOfCirculationCar, motorizationCar: this.motorizationCar}) ) ); }); console.log(promise); return promise; }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 getCar() { const formValue = this.bookingForm.value; const newSiv = new Siv( formValue['licensePlateCar'] ); return this.sivService.addSIV(newSiv).then(() => { this.modelCar = JSON.parse(localStorage.getItem('modelCar')); this.brandCar = JSON.parse(localStorage.getItem('brandCar')); this.dateOfCirculationCar = JSON.parse(localStorage.getItem('dateOfCirculationCar')); this.colorCar = JSON.parse(localStorage.getItem('colorCar')); this.versionCar = JSON.parse(localStorage.getItem('versionCar')); this.motorizationCar = JSON.parse(localStorage.getItem('motorizationCar')); }); }
Je ne comprend pas d'où vient mon erreur. Est il possible d'avoir une explication ?
Partager