如何将过滤器应用于AngularJS中的特定属性?

时间:2016-05-18 09:56:19

标签: angularjs filter

我发现角度过滤器有filter: value但它会搜索整个字符串,例如这里是数据

$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'}
  ];

我想只显示带有字母' e'在他们中。但它也使这些国家与“'在名称中。

如何仅匹配过滤器中的特定属性?

1 个答案:

答案 0 :(得分:3)

您可以通过提供JSON对象来对单个属性执行filter

<强>标记

Name
<input ng-model="search" type="text"/>

<ul>
  <li ng-repeat="item in names | filter: {name: search }">{{item.name}}<li>
</ul>