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.
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.
Use the backTicks:
this.http.get(`/api/getOrder?orderId=${orderId}`)
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.
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.
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}`)