I am making an demo site with angular express seed by Brian Ford (thanks a lot), but after edit a post it does not redirecting to listing url. edit operation doing fine just not redirecting to listing page after hit the submit button . In chrome it is showing Pending in status that never ends... my codes are as bellow:
Angular controller
function EditPostCtrl($scope, $http, $location, $routeParams) {
$scope.form = {};
$http.get('/api/posts/details/' + $routeParams.id).
success(function(data) {
$scope.form = data.post;
});
$scope.editPost = function () {
$http.post('/api/posts/edit/' + $routeParams.id, $scope.form).
success(function(data) {
$location.path('/posts');
});
};
};
Express App
app.post('/api/posts/edit/:id',api.adminLoginCheck,api.editPost);
Api.js
exports.editPost = function (req, res,next) {
console.log("editPost");
var id = req.params.id;
req.body.slug = req.body.title.split(' ').join('-').toLowerCase();
delete req.body._id;
myMongoDb.update({slug:id},'posts',req.body, function(error,results){
if(error){
console.log(error);
res.json(false);
}else{
res.json(true);
}
});
};
What i am doing wrong? Thanks in Advance