0

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?

5
  • 1
    your update button does not call the update method in your controller. add this to your <input> tag - ng-click="update()" Commented Jul 24, 2015 at 10:31
  • It was as simple as that, thank you! If you make an answer, i'll accept Commented Jul 24, 2015 at 11:29
  • Although the update functionality is working again, the fnPtr error is still present Commented Jul 24, 2015 at 11:38
  • can u show the stack trace ? Commented Jul 24, 2015 at 12:23
  • This error mostly occurs when there is a typo in the code. Please check if you have all the brackets right . Commented Jul 24, 2015 at 12:26

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.