Angular (Ionic) – API – How to Post Data ordered

I am working on an APi where a store could define its priorities for a product.

The first one would be "price" obligatory and the others would be its choice of priorities.

I want to send these choices to my Symfony back.
Render of the page

I can see in my consoles the data values which will be sent
Data sent and connection errors

I found only examples on Google and I am not sure how to adapt it to my exercice and why the connection doesn’t work. My Get works on another page with the same endpoint (and a different method inside).

  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()));
  }

Did I miss a step?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *