【问题标题】:Update undefined error for mean-stack?更新平均堆栈的未定义错误?
【发布时间】:2015-04-20 20:52:15
【问题描述】:

我的一些平均堆栈代码有问题。下面显示了代码以及我收到的错误。有没有人有任何建议。这似乎是一个简单的声明错误,但我似乎找不到解决方案

    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;
            });
        };
    }
]);

这是错误:

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)

在加载页面时,我还收到错误 {Uncaught TypeError: Cannot read property 'getToggleElement' of null}。

【问题讨论】:

    标签: angularjs node.js mean-stack


    【解决方案1】:

    调用update 函数的任何外部代码要么未传入参数,要么传入未定义的变量。

    Cannot read '$update' of undefined.
    

    指的是customer.$update。这意味着customer 未定义。它从为updatedCustomer 参数传入的任何参数中接收其值,因此您需要追溯您期望为updatedCustomer 传入的参数。

    调用此update 函数的外部代码实际上是否在调用时传入了一个参数?

    【讨论】:

    • 谢谢... 找到问题了。我只需要输入 customerUpdateCtrl.update(customer);当我只有 customerUpdateCtrl.update();.
    【解决方案2】:

    互补的,

    Uncaught TypeError: Cannot read property 'getToggleElement' of null
    

    来自 ui-bootstrap,不会导致严重错误。

    这里称为问题:https://github.com/angular-ui/bootstrap/issues/2343

    与下拉菜单有关。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      • 1970-01-01
      • 2014-05-17
      • 1970-01-01
      • 2018-11-29
      相关资源
      最近更新 更多