我的一些平均堆栈代码存在问题。代码如下所示,以及我收到的错误。任何人都有任何建议。这似乎是一个简单的声明错误,但我似乎无法找到解决方案
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:无法读取属性&#39; getToggleElement&#39; of null}对页面的负载。
答案 0 :(得分:1)
无论调用update
函数的外部代码是不是传入参数,还是传入未定义的变量。
Cannot read '$update' of undefined.
指的是customer.$update
。这意味着customer
未定义。它从updatedCustomer
参数的任何参数中接收其值,因此您需要追溯您希望传入updatedCustomer
的内容。
调用此update
函数的外部代码实际上是在调用时传入参数吗?
答案 1 :(得分:0)
补充,
Uncaught TypeError: Cannot read property 'getToggleElement' of null
来自ui-bootstrap并且不会导致严重错误。
这里提到了一个问题:https://github.com/angular-ui/bootstrap/issues/2343
与下拉菜单有关。