Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
32
rated 0 times [  39] [ 7]  / answers: 1 / hits: 17321  / 11 Years ago, tue, february 4, 2014, 12:00:00

Hi I have following input



<input type=text class=form-controlb ng-model=item.name id=name placeholder=Enter Name />



And following dropdown



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


Basically what I am trying to do is, when I enter name in the input box if dropdown has that name ints options to show it in dropdown.
I tried to do do filter by name and than orderby name but it doesnt show any on dropdown as selection.
Please let me know how to fix it.
Thanks


More From » angularjs

 Answers
33

something like this may work:



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


http://plnkr.co/edit/Lj0p3wig9JfOM0UkpDrd


[#72720] Monday, February 3, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
katieh

Total Points: 692
Total Questions: 104
Total Answers: 104

Location: Armenia
Member since Sat, Dec 31, 2022
1 Year ago
katieh questions
;