Reputation: 3238
I found angular filter has filter: value
but it would search whole string, for instance here is the data
$scope.names = [
{name:'Jani',country:'Norway'},
{name:'Carl',country:'Sweden'},
{name:'Margareth',country:'England'},
{name:'Hege',country:'Norway'},
{name:'Joe',country:'Denmark'},
{name:'Gustav',country:'Sweden'},
{name:'Birgit',country:'Denmark'},
{name:'Mary',country:'England'},
{name:'Kai',country:'Norway'}
];
I want to only display the names that have the letter 'e' in them. But it's also matching the countries with 'e' in the name.
How to I match to only a specific property in a filter?
Upvotes: 1
Views: 1206
Reputation: 136144
You could do filter
on single property, by having providing JSON object to filter.
Markup
Name
<input ng-model="search" type="text"/>
<ul>
<li ng-repeat="item in names | filter: {name: search }">{{item.name}}<li>
</ul>
Upvotes: 4