How to add search box inside <select> tag with ng-option

Sasika Miyuran picture Sasika Miyuran · Mar 1, 2017 · Viewed 7.1k times · Source

I need to add search box inside the select tag with ng-option.

    <select class="form-control" ng-model="modelname" ng-options="category.id as category.name for category in Categories ng-change="getSubCategory()">
<option><--search box should be here--></option>
</select>

Answer

shubham agrawal picture shubham agrawal · Mar 1, 2017

You could set your search value when user hits the button. live sample: http://plnkr.co/edit/jTRmBH.

template:

 <label>
 Search Value: <input ng-model="filter">*emphasized text*
 </label><br>
 <label>
 Search Key:
 <select ng-model="key">
   <option value="$">Any</option>
   <option value="number">Student Number</option>
   <option value="region">Student Region</option>
 </select> 
 </label>
 <button ng-click="setfilter()">search</button>

javascript:

$scope.setfilter = function() {
  $scope.search = {};
  $scope.search[ $scope.key ] = $scope.filter;
  console.log( $scope.search );
};