By utilizing the code below, I am able to filter results where all entries are displayed on the page:
<body ng-app="">
<div ng-init="friends = [{name:'John', phone:'555-1276'},
{name:'Mary', phone:'800-BIG-MARY'},
{name:'Mike', phone:'555-4321'},
{name:'Adam', phone:'555-5678'},
{name:'Julie', phone:'555-8765'},
{name:'Juliette', phone:'555-5678'}]"></div>
Search: <input ng-model="searchText">
<table id="searchTextResults">
<tr><th>Name</th><th>Phone</th></tr>
<tr ng-repeat="friend in friends | filter:searchText">
<td>{{friend.name}}</td>
<td>{{friend.phone}}</td>
</tr>
</table>
</body>
I am aiming for a jQuery UI autocomplete-style solution where initially there is nothing on the page, but as you type, matching entries appear.
I have attempted to achieve this using ng-show. So far, my only success has been with something like:
ng-show="searchText == 'John'"
This means the content will only display if "John" is typed. Is there a way, perhaps with ng-show or ng-if, to dynamically filter and display matching entries as you type, similar to how the filter works?
I have included an example showing my attempt with the name "John":
<body ng-app="">
<div ng-init="friends = [{name:'John', phone:'555-1276'},
{name:'Mary', phone:'800-BIG-MARY'},
{name:'Mike', phone:'555-4321'},
{name:'Adam', phone:'555-5678'},
{name:'Julie', phone:'555-8765'},
{name:'Juliette', phone:'555-5678'}]"></div>
Search: <input ng-model="searchText">
<table id="searchTextResults">
<tr><th>Name</th><th>Phone</th></tr>
<tr ng-repeat="friend in friends | filter:searchText" ng-show="searchText == 'John'">
<td>{{friend.name}}</td>
<td>{{friend.phone}}</td>
</tr>
</table>
</body>
I have also tried:
ng-show="searchText == searchText"
However, this just displays all items. Can this functionality be achieved with ng-show? Or is there a better approach?