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 trial

JavaScript Building a MEAN Application More TODO with the MEAN Stack Using Angular-wrapped JavaScript APIs

Deano k
Deano k
Courses Plus Student 5,872 Points

Adding a DELETE route

We never added a DELETE route even tho we left a comment for ourselves

How would you go about doing that?


__ROLLER__ Angel
__ROLLER__ Angel
25,606 Points

The 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

1 Answer

Angelica Hart Lindh
Angelica Hart Lindh
19,465 Points

Hi, 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!

This worked like a charm. Thanks!!!!!!