2013-03-26 60 views
1

我有角我怎麼能搜索使用選擇框在angularjs

Any: <input ng-model="search.$"> 
    Student Name only <input ng-model="search.number"> 
    student Region only <input ng-model="search.region"> 

正常工作的事情,這

<li ng:repeat="students in student | filter:search" > 

,但我想使這三個搜索框變成一個搜索框和選擇框像這樣

Any: <input ng-model="search.$"> 

<select> 
    <option value="number">Student Number</option> 
    <option value="region">Student Region</option> 

</select> 

另外我想在用戶點擊搜索按鈕時執行搜索

我該怎麼做

回答

0

當用戶點擊按鈕時,您可以設置您的search值。 直播採樣:http://plnkr.co/edit/jTRmBH

模板:

<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); 
};