Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将输入选择绑定到下拉列表Angularjs_Javascript_Angularjs_Angularjs Directive - Fatal编程技术网

Javascript 将输入选择绑定到下拉列表Angularjs

Javascript 将输入选择绑定到下拉列表Angularjs,javascript,angularjs,angularjs-directive,Javascript,Angularjs,Angularjs Directive,嗨,我有以下输入 和下面的下拉列表 <div class="col-sm-12" ng-model="query"> <select ng-model="item" class="form-control" ng-options="a.name for a in addemployees | filter:name | orderBy:'name'" value="{{a.name}}">

嗨,我有以下输入

和下面的下拉列表

                <div class="col-sm-12" ng-model="query">
                    <select ng-model="item" class="form-control" ng-options="a.name for a in addemployees | filter:name | orderBy:'name'" value="{{a.name}}">
                        <option value="">[Select Employee..]</option>

                    </select>
                </div>

[选择员工..]
基本上,我想做的是,当我在输入框中输入name时,如果dropdown有该名称,那么在dropdown中显示它的ints选项。 我试着按名称过滤,而不是按名称排序,但它没有在下拉列表中显示任何选项。 请让我知道如何修理它。
谢谢

像这样的东西可能有用:

<input type="text" ng-model="text" />
<select ng-model="selectedOption" ng-options="option.name for option in options">
</select>

$scope.options = [{
  name: 'a',
  value: 'value-a'
}, {
  name: 'b',
  value: 'value-b'
}];

$scope.selectedOption = $scope.options[0];

$scope.$watch('text', function(v) {
  for (var i in $scope.options) {
    var option = $scope.options[i];
    if (option.name === v) {
      $scope.selectedOption = option;
      break;
    }
  }
});

$scope.options=[{
名称:‘a’,
value:'value-a'
}, {
名称:‘b’,
值:'value-b'
}];
$scope.selectedOption=$scope.options[0];
$scope.$watch('text',函数(v){
for(var i在$scope.options中){
var option=$scope.options[i];
如果(option.name==v){
$scope.selectedOption=选项;
打破
}
}
});

类似的方法可能会奏效:

<input type="text" ng-model="text" />
<select ng-model="selectedOption" ng-options="option.name for option in options">
</select>

$scope.options = [{
  name: 'a',
  value: 'value-a'
}, {
  name: 'b',
  value: 'value-b'
}];

$scope.selectedOption = $scope.options[0];

$scope.$watch('text', function(v) {
  for (var i in $scope.options) {
    var option = $scope.options[i];
    if (option.name === v) {
      $scope.selectedOption = option;
      break;
    }
  }
});

$scope.options=[{
名称:‘a’,
value:'value-a'
}, {
名称:‘b’,
值:'value-b'
}];
$scope.selectedOption=$scope.options[0];
$scope.$watch('text',函数(v){
for(var i在$scope.options中){
var option=$scope.options[i];
如果(option.name==v){
$scope.selectedOption=选项;
打破
}
}
});

我希望我的例子会有用——)

}))

我希望我的例子会有用——)

}))

            <tr>
            <tr ng-repeat="emp in employees | filter:query">
            <td>{{emp.name}}</td>
            <td>{{emp.company}}</td>
            <td>{{emp.designation}}</td>
        </tr>
angular.module('module3', [])
.controller('testCtrl3', function($scope){
$scope.query = {}
$scope.queryBy = '$'
$scope.items = [
  {
    "name" : "Ananchenko Juriy",
    "company" : "GOOGLE. Ltd",
    "designation" : "Creativ Director"
  },
  {
    "name" : "Ananchenko",
    "company" : "GOOGLE"
  },
  {
    "name" : "Korman Juriy",
    "company" : "GOOGLE. Ltd",
    "designation" : "stager na ispitatelnom sroke"
  }
];
$scope.orderProp="name";