Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDeano k
Courses Plus Student 5,872 PointsAdding a DELETE route
We never added a DELETE route even tho we left a comment for ourselves
How would you go about doing that?
Thanks
Deano k
Courses Plus Student 5,872 PointsThanks mate
1 Answer
Angelica Hart Lindh
19,465 PointsHi, if anyone is still looking for code to add the DELETE route, this is an option:
In the src/api/index.js file:
router.delete('/todos/:id', function(req, res) {
var id = req.params.id;
Todo.remove({'_id': id}, function(err, todo) {
if (err) {
return res.status(500).json({err: err.message});
} else {
res.send('Todo was deleted');
}
});
});
Updated the deleteTodo service located in app/scripts/services/data.js:
this.deleteTodo = function(todo) {
$http.delete('/api/todos/' + todo._id).then(todo);
};
Hope this helps!
Veronica Rivera
32,599 PointsThis worked like a charm. Thanks!!!!!!
__ROLLER__ Angel
25,606 Points__ROLLER__ Angel
25,606 PointsThe code for the completed application includes the JavaScript for adding the DELETE route. I just made a temporary directory to look at the code and it is split between the app/scripts/services/data.js file and the app/scripts/directives/todo.js file.
See the teachers notes of the following video for instructions on getting the final project https://teamtreehouse.com/library/building-a-mean-application/more-todo-with-the-mean-stack/using-angularwrapped-javascript-apis