Search code examples
javascriptangularjsmeanjs

MeanJS stack, debugging Angular error: fnPtr is not a function


I'm learning the MeanJS stack (Mongo, Express, Angular, Node) and writing a simple todo webapp. I can list all todos and create a new one. When I 'edit' a todo, I'm encountering this error:

TypeError: fnPtr is not a function

I'm assuming I have some naming or syntax wrong (based on this and this SO question) The problem is I don't know where to look for wrong naming or bad syntax since the file structure is pretty large ('app' and 'public' maps are 484 files). I don't get into the todo.client.controller nor 'todo.server.controller' update function, as there is a console log there that doesn't get printed. The edit button is a submit input, but I don't know where it goes next.

Code:

Piece form 'edit' page

<div class="form-group">
  <input type="submit" value="Update" class="btn btn-default">
</div>

Client controller:

    // Update existing Todo
    $scope.update = function() {
        console.log('update');
        var todo = $scope.todo;
        todo.$update(function() {
            $location.path('todos/' + todo._id);
        }, function(errorResponse) {
            $scope.error = errorResponse.data.message;
        });
    };

Server controller:

/**Update a Todo*/
exports.update = function(req, res) {
console.log('todo controller');
var todo = req.todo;
todo = _.extend(todo, req.body);
Todo.update({_id: req.body._id}, req.body, function(err, update) {
//todo.save(function(err) {
    if (err) {
        return res.status(400).send({
            message: errorHandler.getErrorMessage(err)
        });
    } else {
        res.json(todo);
    }
});
};

Anyone experienced with the MeanJS stack or Angular that could point me in a direction to start debugging?


Solution

  • You have not added ng-click to the "Update" submit button.

    Change your code to this:

    <div class="form-group">
      <input type="submit" value="Update"  ng-click="update()" class="btn btn-default">
    </div>
    

    As for the fnPtr error, add your full stack trace so that it can be analyzed.

    Also check if your code has closed all the brackets, you are not using same name for 2 variables and typos.