1

i have following record i want filter in ng-repeat by name i enter but its but not working please help me this

  ng-repeat="contact in vm.contacts | filter: {name: vm.chatSearch}

 "userlist": [
        {
            "_id": "59edd7c5ff809c1c4c7a43c2",
            "updatedDatetime": "2017-10-23T11:51:33.106Z",
            "createdDatetime": "2017-10-23T11:51:33.106Z",   
            "user_id": {
                "_id": "59f07d5c935f27764c8d1090",             
                "name": "james"
            },
            "__v": 0
        }
        ]
Sami
  • 117
  • 1
  • 12

3 Answers3

0

Try:

ng-repeat="contact in vm.contacts | filter: {user_id: {name: vm.chatSearch}}"

Demo plunker


Example:

<ul>
  <li ng-repeat="contact in contacts | filter: {user_id: {name: chatSearch}}">
    {{contact.name}}  user_id: {{contact.user_id.name}}
  </li>
</ul>
Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225
0

My following example may helps you

HTML

<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-controller="MyCtrl">
  <input ng-model="results.year">
<div ng-repeat="subject in results.subjects | filter:{grade:'A'}">
    <input ng-model="subject.title" />
</div>
</body>
</html>

JS

  function MyCtrl($scope) {
  $scope.results = {
    year:2013,
    subjects:[
      {title:'English',grade:'A'},
      {title:'Maths',grade:'A'},
      {title:'Science',grade:'B'},
      {title:'Geography',grade:'C'}
    ]
  };
}

Thanks, Arun

Arun Kumar
  • 100
  • 1
  • 2
  • 12
0

You need something like this,

<li ng-repeat="user in vm.contacts  | filter: {user_id: {name: searchterm}}"><span>{{user.user_id.name}}</span></li>

DEMO

 var app = angular.module('myapp',[]);
 app.controller('personController',function(){
  var vm = this;
  vm.contacts =   [
        {
            "_id": "59edd7c5ff809c1c4c7a43c2",
            "updatedDatetime": "2017-10-23T11:51:33.106Z",
            "createdDatetime": "2017-10-23T11:51:33.106Z",   
            "user_id": {
                "_id": "59f07d5c935f27764c8d1090",             
                "name": "james"
            },
            "__v": 0
        }
        ];
 });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app = "myapp" ng-controller = "personController as vm">
 <input ng-model="searchterm"/>
  <ul>
    <li ng-repeat="user in vm.contacts  | filter: {user_id: {name: searchterm}}"><span>{{user.user_id.name}}</span></li>
</ul>
  </div>
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396