deleteTask method is not working in this code. Other methods are working fine. There are no issues with URL. Please help me..
constructor(private http:Http) {
console.log('task service activated');
}
getTasks(){
return this.http.get('http://localhost:3000/api/tasks').map(res => res.json());
}
addTask(newTask){
console.log(newTask);
var headers = new Headers();
headers.append('Content-Type','application/json');
return this.http.post('/api/task',JSON.stringify(newTask),{headers:headers}).map(res => res.json());
}
deleteTask(id){
return this.http.delete('http://localhost:3000/api/task/'+id).map(res => res.json());
}
here is back end code
router.delete('/task/:id',function(req, res, next){
db.tasks.remove({__id: mongojs.ObjectId(req.params.id)}, function(err,task){
if(err){
res.send(err);
}
res.json(task);
});
});
I notice your using __id instead of _id which i think is the mongo default. Try changing that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.