'How do I pass parameters from angular into my nodejs API?
I want to pass the id from Angular in to my "/rating" HTTP-Endpoint, with the following call:
apiUpdateRating(id){
return this.http.get('http://localhost:8080/rating', {
params:id
});
}
But if console.log my "req.params" in my NodeJs API, I see that it is empty:
app.get('/rating',function(req,res){
res.send('RParam: '+req.params);
});
Could anyone tell me where my mistake is? I think I do not pass the id properly in the URL, but don't know how to do it properly.
Solution 1:[1]
Try this:
apiUpdateRating(id: number | string) {
return this.http.get('http://localhost:8080/rating', {
params: { id: id },
});
}
You need to specify both the key and value of a parameter. params is an object containing these key-value pairs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chris Hamilton |
