在Angular中:从下拉列表中选择选项时,我想在搜索字段中搜索该值

时间:2017-01-31 14:44:26

标签: angularjs dropdown nssearchfield

我是棱角分明的新手,我被卡住了...... 我想创建一个下拉列表,如this image所示,其中文本框中的占位符取决于下拉列表中的所选选项。

我的HTML是

<select class="selectpicker" ng-options="search for search in searchCriteria" ng-model="searchWith">
    <option value="">Select : </option>
</select>

<input type="text" ng-model="searchName" class="form-control" placeholder="Search with {{searchWith}}" />

我的控制器定义为:

var companyInfo = angular.module('companyInfo', []);

companyInfo.controller('searchExample', ['$scope',   '$http',function($scope, $http){
   $scope.searchCriteria = ['Name', 'Employee Id', 'Designation', 'Email','Phone No']

   $http.get("data/data.json").then(function(data){
       $scope.employeeDetails= data.data;       
   });

   $scope.searchInTable = function(searchName){
      $scope.searchVal = searchName;
   }    
}]);

1 个答案:

答案 0 :(得分:0)

你可以尝试这个data-ng-change使用指定的函数

更改select时绑定事件
    <select class="selectpicker" ng-options="search for search in searchCriteria" ng-model="searchWith" data-ng-change="search()">
    <option value="">Select : </option>
</select>

<input type="text" ng-model="searchName" class="form-control" placeholder="Search with {{searchWith}}" />

并在您的控制器中

    $scope.search = function(){
  $scope.searchName = $scope.searchWith;
}