Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

AngularJS - filter by exact values

Article:
Viewed:  1887 
Posted On:  20/08/2015 20:49:22 
How we can get result with exact search text using Filter in AngularJS ? 

 

I was working on a requirement and I need to use filter in AngularJS but in my application Filter was working as a Like statement For Exp like below:

<ul ng-repeat="emp in Employees | filter: { EMP_ID: '2' } | orderBy: 'name' ">
   <li>{{emp.name}}</li>
  </ul>
 
$scope.Employees = [
{ name: "Rahul K Saxena", EMP_ID: 2 },
{ name: "Shambhu Sharma", EMP_ID: 55 },
{ name: "Abhishek Nigam", EMP_ID: 20 },
{ name: "Yogesh Gupta", EMP_ID: 22 },
{ name: "Rakesh Dixit", EMP_ID: 41 },
{ name: "Shraddha", EMP_ID: 45 },
{ name: "Shweta", EMP_ID: 71 },
{ name: "Mehak", EMP_ID: 43 },
{ name: "Mayank Dhulekar", EMP_ID: 32 },
{ name: "Saurabh Mehrotra", EMP_ID: 56 }
];

 

Then Result:

Rahul K Saxena
Abhishek Nigam
Yogesh Gupta
Mayank Dhulekar
 

So to get the exact Match I use filter:{EMP_ID:2}:true Like Below:

<body ng-app="myApp" ng-controller="myCtrl">
  <ul ng-repeat="emp in Employees | filter:{ EMP_ID:2}:true | orderBy: 'name' ">
      <li>{{emp.name}}</li>
  </ul>
</body>
 

Now Run your application: And Result is as Expected:

Rahul K Saxena

 

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us