简体   繁体   English

如何在里面添加搜索框 <select>用ng-option标记

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

I need to add search box inside the select tag with ng-option. 我需要在带有ng-option的select标记内添加搜索框。

    <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>

You could set your search value when user hits the button. 您可以在用户点击按钮时设置search值。 live sample: http://plnkr.co/edit/jTRmBH . 实时示例: 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: JavaScript的:

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

You can't with standard html. 您不能使用标准html。 You'll have to create something custom - something along these lines. 您必须创建一些自定义内容-遵循这些原则。

<ul class="custom-select">
    <li class="custom-select__option" ng-repeat="o in $ctrl.options"><input type="search"/></li>
<ul>

It won't be hard to create, but that's the direction you'll need to go. 创建起来并不难,但这就是您需要走的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM