Not calling the nodejs restapi from angular services.
users.component.ts
editUser(){
const updatedUser ={
_id: this._id,
name: this.name,
email: this.email,
mobile: this.mobile
}
console.log(updatedUser)
this.usersService.updateUser(updatedUser)
this.readUsers();
}
users.service.ts
updateUser(updatedUser){
return this.http.post('http://localhost:3000/edit/' + updatedUser._id, updatedUser).pipe(
map(res => res.json())
)
}
nodejs restapi
userRoutes.js
const edituser = []
router.post('/edit/:id', (req, res) => {
console.log('fromEditRoute')
User.findByIdAndUpdate({_id : req.params.id}, req.body)
.then(result => {
edituser.push(result)
res.json(edituser)
})
.catch(error => {
console.log(error);
res.status(500).json({message: 'An Error Occured'});
})
console.log('hello')
})
console.log() in routes is not even printed.
Every help will be appreciated, Thank You!!
updateUserwith subscription? show us the call to this function