I have a form where I want the user to be able to enter in search terms into textboxes, and then click a button to search the list. Is it possible to do something like this with ng-repeat and a button click? I'm really new to Angular, and I'm unsure if I can use it for this type of functionality. I have a little bit of code:
HTML
<div>
<input ng-model="filterSearch.address" />
<input ng-model="filterSearch.city" />
<button ng-click="">Search</button>
<table>
<thead>
<tr>
<th>
Address
</th>
<th>
City
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="search in vm.searches | filter: filterSearch">
<td>
{{ search.address }}
</td>
<td>
{{ search.city }}
</td>
</tr>
</tbody>
</table>
Controller:
(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"
}
];
}
})();
If anyone could point me in the right direction that would be great. Thanks.
Updated code:
<div>
<input ng-model="searchModel.address" />
<input ng-model="searchModel.city" />
<button ng-click="filterSearch = searchModel">Search</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>