在另一个函数中调用同一范围内的函数 -AngularJS - 错误
Calling a function in same scope in another function -AngularJS - Error
我有这段代码,我做了一个刷新功能,清楚地说明了目的。我还必须刷新其他统计数据,但我无法在下面的 "refresh" 函数中调用它,即使它们在 same 范围内也是如此。我确定我的调用是正确的,但控制台不断给出以下 错误:
ReferenceError: getAllCustomers 未定义
$scope.getAllCustomers = new function(){
$http.post('
<?php echo site_url('angularjs/get_users_by_type/'); ?>',
{userType:'C'}).then(function(response) {
$scope.totalCustomer = response.data.count;
}, function(response) {
console.log(response);
// called asynchronously if an error occurs
// or server returns response with an error status.
});
};
// getAllCustomer etc all defined before this function but the following errors keeps coming on the console that getAllCustomers is not a function.
$scope.refresh = new function(){
getAllCustomers();
};
声明函数时去掉new
关键字,应该是
$scope.getAllCustomers = function()
像这样检查您的代码:
$scope.getAllCustomers = function(){
$http.post('
<?php echo site_url('angularjs/get_users_by_type/'); ?>',
{userType:'C'}).then(function(response) {
$scope.totalCustomer = response.data.count;
}, function(response) {
console.log(response);
});
};
$scope.refresh = function(){
$scope.getAllCustomers();
};
我有这段代码,我做了一个刷新功能,清楚地说明了目的。我还必须刷新其他统计数据,但我无法在下面的 "refresh" 函数中调用它,即使它们在 same 范围内也是如此。我确定我的调用是正确的,但控制台不断给出以下 错误:
ReferenceError: getAllCustomers 未定义
$scope.getAllCustomers = new function(){
$http.post('
<?php echo site_url('angularjs/get_users_by_type/'); ?>',
{userType:'C'}).then(function(response) {
$scope.totalCustomer = response.data.count;
}, function(response) {
console.log(response);
// called asynchronously if an error occurs
// or server returns response with an error status.
});
};
// getAllCustomer etc all defined before this function but the following errors keeps coming on the console that getAllCustomers is not a function.
$scope.refresh = new function(){
getAllCustomers();
};
声明函数时去掉new
关键字,应该是
$scope.getAllCustomers = function()
像这样检查您的代码:
$scope.getAllCustomers = function(){
$http.post('
<?php echo site_url('angularjs/get_users_by_type/'); ?>',
{userType:'C'}).then(function(response) {
$scope.totalCustomer = response.data.count;
}, function(response) {
console.log(response);
});
};
$scope.refresh = function(){
$scope.getAllCustomers();
};