Javascript ng click或ng submit未调用控制器方法

Javascript ng click或ng submit未调用控制器方法,javascript,angularjs,asp.net-web-api,asp.net-web-api2,Javascript,Angularjs,Asp.net Web Api,Asp.net Web Api2,我刚刚开始学习Angular JS并下载了 为了我的手。到目前为止,我已经尝试调用我的Web API来返回所有记录,并与视图绑定,效果很好。 现在,我尝试添加一个带有提交按钮的文本框来搜索输入的文本,这似乎是angular app的基本功能,但单击提交按钮无法调用控制器方法: <form ng-submit="getSearchResuls(id)"> <input type="text" data-ng-model="id" class=" noval

我刚刚开始学习Angular JS并下载了 为了我的手。到目前为止,我已经尝试调用我的Web API来返回所有记录,并与视图绑定,效果很好。 现在,我尝试添加一个带有提交按钮的文本框来搜索输入的文本,这似乎是angular app的基本功能,但单击提交按钮无法调用控制器方法:

    <form ng-submit="getSearchResuls(id)">
        <input type="text" data-ng-model="id" class=" novalidate form-control" />
        <input type="submit" value="Search"  />
    </form>
我还尝试在表单标签中添加ng控制器,但仍然没有成功。 能否请您发表宝贵意见以解决此问题?

需要将函数GetSearchResults添加到您的范围中。因此,首先,确保“$scope”作为injectParams列出,然后将$scope作为CustomerController的参数包括在内。然后像这样做:

$scope.getSearchResuls = function (id) {
   //the rest of your code here
}

感谢您的回答,我在我的控制器中注入了“$scope”,然后将其包括在我的控制器中,如var CustomersController=function$scope、$location、$filter、$window、$timeout、authService、dataService、modalService{然后定义了GetSearchResults方法,但我得到了错误引用error:GetSearchResults没有定义,有什么线索吗?我继续做了一个JSFIDLE。我怀疑你的代码可能还有其他错误。请随意提供另一个JSFIDLE,我可以更好地查看你的所有代码。感谢JSFIDLE链接,我搞乱了JSFIDLE这也是一个愚蠢的错误,使用onClick而不是ng Click,请原谅!现在的新问题是我想访问视图中的范围变量$scope.customers=data.results。我试图访问它,很高兴看到ngClick工作。如果可能的话,请创建一个JSFIDLE。我注意到您缺少一个双引号,可能还有一些还有别的,但我不能从提供的摘录中看出。
var injectParams = ['$location', '$filter', '$window',
                    '$timeout', 'authService', 'dataService', 'modalService'];

 var CustomersController = function ($location, $filter, $window,
    $timeout, authService, dataService, modalService) {

function getSearchResuls(id) {
        dataService.getSearchResults(id, vm.currentPage - 1, vm.pageSize)
            .then(function (data) {
                vm.totalRecords = data.totalRecords;
                vm.customers = data.results;
                filterCustomers(''); //Trigger initial filter

                $timeout(function () {
                    vm.cardAnimationClass = ''; //Turn off animation since it won't keep up with filtering
                }, 1000);

            }, function (error) {
                $window.alert('Sorry, an error occurred: ' + error.data.message);
            });
    }
};

CustomersController.$inject = injectParams;

angular.module('customersApp').controller('CustomersController', CustomersController);

}());
$scope.getSearchResuls = function (id) {
   //the rest of your code here
}