REST API Delete request from Angular to Express Server not working
<p>I have modeled my code using the Mean Stack as laid out by Joe Eames in a Pluralsight class.  I am still learning so please excuse my terminology.</p>

<p>The $stateprovider and routing is working for bulk queries and creating records but when I try to perform any function with a particular id I get a 404 error.  When I print out the id I can see that it the right id on the client but it is not being passed to the server.  Somewhere I must have the wrong syntax.  Code below focuses on the Delete option but I am sure I am having the same problem with update and single record return queries.</p>

<pre><code>// flQuestionCrudCtrl.js
angular.module('app').controller('flQuestionCrudCtrl',function(flConstructDataService, flQuestionDataService, flQuestionCrud, flCachedReferenceData,flCachedQuestions, flAnswer, $scope, $location, $q, flIdentity, flNotifier,$timeout, $state) {
//Q = require('q');
var currentQuestionData;
var answers;
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var today = month + "/" + day + "/" + year;
var oID = flIdentity.currentUser._id;


var setCurrentQuestionData = function() {
    currentQuestionData = {
        question_id: flQuestionDataService.getNewQuestionId(),
        construct_id: flQuestionDataService.getNewConstructId(),
        statement: flQuestionDataService.getNewStatement(),
        sequenceNo: flQuestionDataService.getNewSequenceNo(),
        componentType: flQuestionDataService.getNewComponentType(),
        weight: flQuestionDataService.getNewWeight(),
        imageURL: flQuestionDataService.getNewImageURL(),
        answers: flQuestionDataService.getNewAnswers(),
        createDate:flQuestionDataService.getNewCreateDate() ,
        lastUpdateId: flQuestionDataService.getNewLastUpdateId(),
        lastUpdateDate: today
    };
};

$scope.deleteQuestion = function() {
    console.log("flConstructCrudCtrl.deleteQuestion - Start Delete Question");
    setCurrentQuestionData();

    flQuestionCrud.deleteCurrentQuestion(currentQuestionData.question_id)
        .then(function(data) {
            // work with data here
            console.log("flQuestionCrudCtrl - Delete Success " + data);
            console.log("flQuestionCrudCtrl - Delete Success Statement " + data.statement);
            console.log("flQuestionCrudCtrl - Delete Success Question id " + data._id);
            flQuestionDataService.setInitialized(false);
            flCachedQuestions.empty();
            $state.go('questions');
            //$state.go('questionCreate');
        })
  };
});


 //flQuestionCrud

angular.module('app').factory('flQuestionCrud',function($http, $q, $state, $timeout, flQuestion ){

return {
    deleteCurrentQuestion: function(currentQuestionID) {
        console.log("flQuestionCrud - Before, flQuestion.delete");
        console.log("flQuestionCrud - currentQuestionData = " + currentQuestionID);
        var deferred = $q.defer();

        flQuestion.delete(currentQuestionID, function(data) {
            if (data){
                // whatever we resolve the promise with will be passed
                // to the `then` handler in the controller
                console.log("flQuestionCrud - Delete Success " + data);
                console.log("flQuestionCrud - Delete Success Statement " + data.statement);
                console.log("flQuestionCrud - Delete Success Question id " + data._id);
                deferred.resolve(data);
            }
            else {
                deferred.reject("Error Deleting Data");
            }
        });
        return deferred.promise;
    }
}
});


//flQuestion
angular.module('app').factory('flQuestion',function($resource){
var QuestionResource = $resource('/api/questions/:id', {_id: "@id"}, {

    //update: {method:'PUT', isArray:false},
    query: { method: 'GET', isArray: true },
    create: { method: 'POST' },
    update: { method: 'PUT', params: {id: '@id'}},
    delete: { method: 'DELETE', params: {id: '@id'}}
});

return QuestionResource;
});


//app.js
angular.module('app',['ngResource', 'ui.router','xeditable', 'inputDropdown']);

// Can add the $logProvider before the $routeProvider to add debug  capabilities
//    app.config(function($logProvider, $stateProvider, $locationProvider, $urlRouterProvider ){
angular.module('app').config(function($logProvider, $stateProvider, $locationProvider, $urlRouterProvider ){
$logProvider.debugEnabled(true);
var routeRoleChecks = {
    admin: {auth: function(flAuth){
        return flAuth.authorizeCurrentUserForRoute('admin')
    }},
    user: {auth: function(flAuth){
        return flAuth.authorizeAuthenticatedUserForRoute()
    }}
};

$locationProvider.html5Mode({
        enabled: true,
        requireBase: false, //required to specify base of application in our HTML
        rewriteLinks: true  //Angular will rewrite URLs as necessary (add# to older browsers)
});


$stateProvider

    .state('questionCreate', {
        url: '/questionCreate',
        views: {
            'content-header': {
                templateUrl: '/app/main/main-header',
                controller: 'flMainCtrl',
                caseInsensitivitieMatch: true
            },
            'content-banner': {
                templateUrl: '/app/constructs/construct-banner',
                controller: 'flConstructCrudCtrl',
                caseInsensitivitieMatch: true
            },
            'content-main': {
                templateUrl: '/app/questions/question-crud',
                controller: 'flQuestionCrudCtrl',
                controllerAs: 'questionCreate',
                caseInsensitivitieMatch: true
            },
            'content-left': {
                templateUrl: '/app/questions/question-menu-left',
                controller: 'flQuestionCrudCtrl',
                //controllerAs: 'questionCreate',
                caseInsensitivitieMatch: true
            },
            'content-right': {
                templateUrl: '/app/questions/question-menu-right',
                controller: 'flQuestionCrudCtrl',
                //controllerAs: 'questionCreate',
                caseInsensitivitieMatch: true
            },
            'content-footer': {
                templateUrl: '/app/main/main-footer',
                controller: 'flMainCtrl',
                caseInsensitivitieMatch: true
            }
        }
    })
    .state('questionUpdate', {
        url: '/questionUpdate',
        views: {
            'content-header': {
                templateUrl: '/app/main/main-header',
                controller: 'flMainCtrl',
                caseInsensitivitieMatch: true
            },
            'content-banner': {
                templateUrl: '/app/constructs/construct-banner',
                controller: 'flConstructCrudCtrl',
                caseInsensitivitieMatch: true
            },
            'content-main': {
                templateUrl: '/app/questions/question-crud',
                controller: 'flQuestionCrudCtrl',
                controllerAs: '/questionUpdate/:id',
                caseInsensitivitieMatch: true
            },
            'content-left': {
                templateUrl: '/app/questions/question-menu-left',
                controller: 'flQuestionCrudCtrl',
                //controllerAs: 'questionCreate',
                caseInsensitivitieMatch: true
            },
            'content-right': {
                templateUrl: '/app/questions/question-menu-right',
                controller: 'flQuestionCrudCtrl',
                //controllerAs: 'questionCreate',
                caseInsensitivitieMatch: true
            },
            'content-footer': {
                templateUrl: '/app/main/main-footer',
                controller: 'flMainCtrl',
                caseInsensitivitieMatch: true
            }
        }
    })
    .state('questionDelete', {
        url: '/questionDelete',
        views: {
            'content-header': {
                templateUrl: '/app/main/main-header',
                controller: 'flMainCtrl',
                caseInsensitivitieMatch: true
            },
            'content-banner': {
                templateUrl: '/app/constructs/construct-banner',
                controller: 'flConstructCrudCtrl',
                caseInsensitivitieMatch: true
            },
            'content-main': {
                templateUrl: '/app/questions/question-crud',
                controller: 'flQuestionCrudCtrl',
                controllerAs: 'questionDelete',
                caseInsensitivitieMatch: true
            },
            'content-left': {
                templateUrl: '/app/questions/question-menu-left',
                controller: 'flQuestionCrudCtrl',
                //controllerAs: 'questionCreate',
                caseInsensitivitieMatch: true
            },
            'content-right': {
                templateUrl: '/app/questions/question-menu-right',
                controller: 'flQuestionCrudCtrl',
                //controllerAs: 'questionCreate',
                caseInsensitivitieMatch: true
            },
            'content-footer': {
                templateUrl: '/app/main/main-footer',
                controller: 'flMainCtrl',
                caseInsensitivitieMatch: true
            }
        }
    })

        $urlRouterProvider.otherwise('home');
});

angular.module('app').run(function($rootScope, $location){
$rootScope.$on('$stateChangeError', function(evt, current, previous, rejection){

    if (rejection === 'not authorized'){
        $location.path('/');
    }
});
});

app.run(function(editableOptions) {
editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
});


//Server Code
//route.js
var questions = require('../controllers/questions'),


module.exports = function(app){

app.get('/api/questions', questions.getQuestions);
app.get('/api/questions/:id', questions.getQuestionById);
app.post('/api/questions', questions.createQuestion);
app.put('/api/questions/:id', questions.updateQuestion);
app.delete('/api/questions/:id', questions.deleteQuestion);

}


//question.js
var Question = require('mongoose').model('Question');

exports.deleteQuestion = function(req, res){
    //var questionDelete = req.body;
    console.log("At Server ready to Delete");
    console.log("questionDelete req.params = " + req.params);
    console.log("questionDelete req.params.id = " + req.params.id);
    //console.log("questionDelete.statement = " + req.params.statement);
    //console.log("questionDelete.componentType" + req.params.componentType);


    //var mongoose = require('mongoose');
    //var objId = mongoose.Types.ObjectId(questionId);

Question.findOneAndRemove({_id:req.params.id}, function (err,oldQuestion)
{
    if(err) {
        console.error('ERROR!' + err);
        res.send(null);
    }else{
        console.log("Return Value = " + oldQuestion);
        res.send(oldQuestion);
    }
});
console.log("At Server After Delete -  This should not print");
};
</code></pre>