Hello Kartik,
There are three ways to get parameters to express:
- req.query --> this case, query parameters
- req.body --> post request body payload
- req.params --> /:someParam in url params
It should be req.query.searchKey.
Change the query to like this: u need to pass different params with different names:
this.http.get('http://localhost:3000/api/change_life_cycle2',
{
params:{
searchKey: this.enteredValue
}
}).subscribe(response => {
console.log(response);
this.newPost = response
});
In API side read the params in the request like this:
app.get("/api/change_life_cycle2", (req, res, next) => {
console.log(req.body)
Change_life_cycle.find({ orgChange: req.query.searchKey }).then(documents => {
res.status(200).json({
message: "Posts fetched successfully!",
posts: documents
});
});
});
Hope it helps!!
To know more about Angular, Join best Angular certification course today.
Thank you!!