Alex J
Alex J

Reputation: 3183

Update undefined error for mean-stack?

I am having a problem with some of my mean stack code. The code is shown below along with the error I am receiving. Dos anyone have any suggestions. It seems to be a simple declaration error but I can not seem to find a solution

    customersApp.controller('CustomersUpdateController', ['$scope', 'Customers', '$log',
    function($scope, Customers, $log) {
        // Update existing Customer
        this.update = function(updatedCustomer) {
            var customer = updatedCustomer;
            customer.$update(function() {
            $log.info('Made it inside ok');
                //Dont want to take user anywhere else
//              $location.path('customers/' + customer._id);
            }, function(errorResponse) {
                $scope.error = errorResponse.data.message;
            });
        };
    }
]);

This is the error:

TypeError: Cannot read property '$update' of undefined
at update (http://localhost:3000/modules/customers/controllers/customers.client.controller.js:115:12)
at http://localhost:3000/lib/angular/angular.js:10880:21
at http://localhost:3000/lib/angular/angular.js:10655:29
at http://localhost:3000/lib/angular-touch/angular-touch.js:441:9
at Scope.$eval (http://localhost:3000/lib/angular/angular.js:12788:28)
at Scope.$apply (http://localhost:3000/lib/angular/angular.js:12886:23)
at Scope.$delegate.__proto__.$apply (<anonymous>:855:30)
at HTMLButtonElement.<anonymous> (http://localhost:3000/lib/angular-touch/angular-touch.js:440:13)
at http://localhost:3000/lib/angular/angular.js:2853:10
at forEach (http://localhost:3000/lib/angular/angular.js:325:18)

I also get an error {Uncaught TypeError: Cannot read property 'getToggleElement' of null} on the load of the page.

Upvotes: 0

Views: 491

Answers (2)

R&#233;mi Becheras
R&#233;mi Becheras

Reputation: 15222

Complementary, the

Uncaught TypeError: Cannot read property 'getToggleElement' of null

comes from ui-bootstrap and causes no critical errors.

It refered as an issue here: https://github.com/angular-ui/bootstrap/issues/2343

It is related to the dropdown menu.

Upvotes: 0

Luke
Luke

Reputation: 155

Whatever outside code that is calling the update function is either not passing in an argument, or it is passing in a variable that is undefined.

Cannot read '$update' of undefined.

refers to customer.$update. It means that customer is undefined. It receives its value from whatever argument is passed in for theupdatedCustomer parameter, so you need to trace back what you expect to be passing in for updatedCustomer.

Is the external code that calls this update function in fact passing in an argument at call time?

Upvotes: 1

Related Questions