angularjs - MEAN stack user delete -
i've got users list delete button on /users
url. delete route looks this:
app.route('/users/:userid') .get(users.read) .put(users.updatebyid) .delete(users.delete); app.param('userid', users.userbyid);
but problem is, delete button calling delete on /users
url, i'm getting delete http://localhost:3000/users 404 (not found)
. how can solve problem? controller remove() function can see below. how can pass '/user/' + user._id
it? user removed correctly scope :(
$scope.remove = function(id) { var user = $scope.users[id]; var modaloptions = { closebuttontext: 'cancel', actionbuttontext: 'delete user', headertext: 'delete ' + user.displayname + '?', bodytext: 'are sure want delete user?' }; modalservice.showmodal({}, modaloptions).then(function() { if (user) { user.$remove(); (var in $scope.users) { if ($scope.users[i] === user) { $scope.users.splice(i, 1); // remove item scope } } } }); };
user service basic mean.js installation
angular.module('users').factory('users', ['$resource', function($resource) { return $resource('users', {}, { update: { method: 'put' } }); } ]);
angular resources default have following methods: get, save, query, remove, delete. unless otherwise specified, not pass param in url way need them to. in case, need specify remove
method , ensure param gets passed in url.
angular.module('users').factory('users', ['$resource', function($resource) { return $resource('users', {}, { update: { method: 'put' }, remove: { method: 'delete', url: 'users/:id', params: {id: '@_id'} } }); } ]);
this assumes user objects have _id
property, common in mean stack. should setup save , update same way.