1

I have problem in sending id from front to backend.

this.http.get('${this.api/getOrder}/${orderId}') but it is giving garbage value.

this.http.get('/api/getOrder?orderId=${orderId}')

I expect this orderId in api to update the order.

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317

3 Answers3

3

Use the backTicks:

this.http.get(`/api/getOrder?orderId=${orderId}`)

Image showing backticks

Template literals are string literals allowing embedded expressions.

These are enclosed by the back-tick (``).Template literals can contain placeholders. These are indicated by the dollar sign and curly braces (${expression}). The expressions in the placeholders and the text between the back-ticks () get passed to a function. The default function just concatenates the parts into a single string. You can use multi-line strings and string interpolation features with them.

nircraft
  • 8,242
  • 5
  • 30
  • 46
1

replace

this.http.get('/api/getOrder?orderId=${orderId}')

with

this.http.get(`/api/getOrder?orderId=${orderId}`)

you should use backtick instead of single quotation if you have an expression inside a string.

Ali Badr
  • 128
  • 1
  • 10
0

Simplest way to send parameters in get request:

Before ES6

this.http.get("/api/getOrder?orderId="+orderId)

After ES6, this can also be used:

this.http.get(`/api/getOrder?orderId=${orderId}`)

khush
  • 2,702
  • 2
  • 16
  • 35