2 pièce(s) jointe(s)
Angular (Ionic) - API - Comment poster un tri de données?
Hello,
Je m'entraine Angular en suivant un cours Udemy et là, j'ai eu envie de tester un truc mais je bloque.
Sur ma page, j'ai bien les éléments que je veux trier
Pièce jointe 583996
Dans la console, j'ai les valeurs et les éléments affichés
Pièce jointe 583997
Je veux envoyer ces données à Symfony. Le Get fonctionne bien depuis une autre page url avec un code similaire
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| ngOnInit() {
try {
// if (this.priosService == null) return throwError('null data');
this.http.get<any[]>(this.apiUrl)
.subscribe(data => {
this.prios = data;
});
// }
// return this.data;
} catch(data) {
console.log("Tombé à l'eau");
console.log(data);
}
} |
est ce que la méthode d'envoyer ces données comme cela peut fonctionner:
Code:
1 2 3 4 5 6 7 8 9 10 11
| postData() {
let url = `${this.apiUrl}/`;
this.http
.post(url, {
prio1: "price",
prio2: this.item[0],
prio3: this.item[1],
prio4: this.item[2]
})
.subscribe(res => console.log(this.http.post()));
} |
Le code global est :
Code:
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| prios: Prios[];
apiUrl = 'http://localhost:8000/api/prio';
listItems: any;
item = [
// {value: 'Price', viewValue: ' Price'},
{ value: "New", viewValue: "Release Date of product" },
{
value: "Size",
viewValue: "Size of product"
},
{
value: "Area",
viewValue: "Product delivery area"
}
];
constructor(private http: HttpClient) {
this.listItems = [
// 'Price',
"Release Date of product",
"Size of product",
"Product delivery area"
];
}
ngOnInit() {
this.http.get<any[]>(this.apiUrl).subscribe(data => {
this.prios = data;
});
}
postData() {
let url = `${this.apiUrl}/`;
this.http
.post(url, {
prio1: "price",
prio2: this.item[0],
prio3: this.item[1],
prio4: this.item[2]
})
.subscribe(res => console.log(this.http.post()));
} |
J'ai aussi mis sur stackblitz mais il est non fonctionnel
https://stackblitz.com/edit/ionic-wh...t.component.ts