My data setup appears as follows:
$scope.friends = [
{
name: function() {
return 'steve';
},
number: function() {
return 555;
}
},
{
name: function() {
return 'mary';
},
number: function() {
return 555;
}
},
{
name: function() {
return 'jo';
},
number: function() {
return 888;
}
}
]
I am trying to filter the data in ng-repeat
based on text input. I have attempted the following:
<table id="searchTextResults">
<tr><th>Name</th><th>Phone</th></tr>
<tr ng-repeat="friend in friends | filter:search">
<td>{{friend.name}}</td>
<td>{{friend.number}}</td>
</tr>
</table>
The input is defined as
<input type="text" ng-model="search.name"/>
.
However, the filter does not work. After modifying the data structure like this,
$scope.friends = [
{
name:'steve',
number: 555
},
{
name:'marry',
number: 555
},
{
name:'steve',
number: 888
}
]
only then it works. But my intention is to keep my data structure as it is.
I would appreciate any help or advice on how to apply a filter with the current data structure provided above.