2014-12-07 85 views
0

我遇到了一些平均堆栈代码的问题。代码如下所示以及我收到的错误。有没有人有任何建议。这似乎是一个简单的声明错误,但我似乎无法找到解决的办法更新平均堆栈的未定义错误?

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) 

我也得到一个错误{遗漏的类型错误:无法读取属性“getToggleElement 'null}在页面的负载上。

回答

1

不管调用update函数的外部代码是不是传入一个参数,或者它传递一个未定义的变量。

Cannot read '$update' of undefined. 

指的是customer.$update。这意味着customer未定义。它从参数updatedCustomer传入的参数中收到它的值,所以你需要追溯你期望通过的参数为updatedCustomer

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

+0

谢谢...发现问题。我只需要把customerUpdateCtrl.update(customer);当我所有的是customerUpdateCtrl.update();. – 2014-12-08 00:45:31