javascript - Angular filter expression -


i'm working on filter expression filters data-id of element.

the problem i'm having filter return multiple values if other id's have same digits positioned elsewhere (i.e. filter 12 returns 12, 123, 1234). i'd return 1 element exact value of 12.

js

angular.module('app', []).controller('testctrl', function($scope) { $scope.customers = [   {     id: 12,     name: 'customer 1 - 1'   },   {     id: 123,     name: 'customer 2 - 12'   },   {     id: 1234,     name: 'customer 3 - 12'   }  ]; }); 

html

filter: <input ng-model="filtercustomer" /> <hr/> <select size="4" ng-options="customer customer.name customer in customers | filter:{id: filtercustomer} track customer.id" ng-model="customerselection"> </select> 

i've tried adding following expression filter match digit length... it's not working expected

filter:{id:filterfsaiscustomer.tostring().length} 

here plunker.

it should used strict checking adding true inside filter, should have convert value in integer making input field type="number" parse int.

markup

<input type="number" ng-model="filtercustomer" />  <select size="4"    ng-options="customer customer.name customer in customers | filter:{id: filtercustomer}:true track customer.id"    ng-model="customerselection"> </select> 

working plunkr

edit

to enable filter after value entered in textbox become conditional base strict checking | filter:{id: filtercustomer}:filtercustomer>0

<select size="4"    ng-options="customer customer.name customer in customers | filter:{id:  filtercustomer}:filtercustomer>0  track customer.id"    ng-model="customerselection"> </select> 

updated plunkr


Comments