【发布时间】:2014-12-11 05:52:13
【问题描述】:
刚开始学习Angular JS,下载了Dan Wahlin's Customer Manager App 为了我的手。到目前为止,我已经尝试调用我的 Web API 来返回所有记录并与运行良好的 View 绑定。 现在我正在尝试添加一个带有提交按钮的文本框来搜索输入的文本,这似乎是 Angular 应用程序的非常基本的功能,但无法通过单击提交按钮调用控制器方法:
<form ng-submit="getSearchResuls(id)">
<input type="text" data-ng-model="id" class=" novalidate form-control" />
<input type="submit" value="Search" />
</form>
我也试过了:
<form >
<input type="text" data-ng-model="id" class=" novalidate form-control" />
<input type="submit" value="Search" onclick="getSearchResuls(id)" />
</form>
两者都不适用于我的以下控制器定义 (函数 () {
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);
}());
我也尝试在 form 标签中添加 ng-controller,但仍然没有成功。 请问您的宝贵意见可以解决这个问题吗?
【问题讨论】:
标签: javascript angularjs asp.net-web-api asp.net-web-api2