0
嗨我有一个表单,可以搜索数据输入到文本框,然后单击提交按钮。它在第一次完美运行,但是当我尝试清除这些值并进行第二次搜索时,它会开始显示数据而无需单击按钮。它只需在文本框中输入即可进行双向绑定。我需要它只在按钮被点击时才工作。这里是我的代码:AngularJS搜索按钮
HTML
<form name="form" id="form" novalidate>
<div>
<input ng-model="searchModel.address" />
<input ng-model="searchModel.city" />
<button type="submit" ng-click="filterSearch = searchModel">Search</button>
<button type="reset">Reset</button>
<table>
<thead>
<tr>
<th>
Address
</th>
<th>
City
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="search in vm.searches | filter:{'address': filterSearch.address, 'city': filterSearch.city}">
<td>
{{ search.address }}
</td>
<td>
{{ search.city }}
</td>
</tr>
</tbody>
</table>
</div>
控制器:
(function() {
'use strict'
angular
.module('crm.ma')
.controller('AdvancedSearchCtrl', AdvancedSearchCtrl);
function AdvancedSearchCtrl() {
var vm = this;
vm.searches = [
{
"address": "202 This St",
"city": "Columbus"
},
{
"address": "205 That St",
"city": "Dayton"
}
];
}
vm.SearchModel = function() {
var vm = this;
vm.filterSearch = angular.copy(searchModel);
};
})();
你'NG-click'只是做一个参考分配。你的意思是做一些像'ng-click =“SearchModel();”'这实际上是深层复制? – ryanyuyu
@ryanyuyu当我这样做时,搜索按钮根本不起作用。 – hollyquinn