0

Thanks for reading my question. I know there are similar questions, but I have not solved my question, so I publish my question. I want to assign a value to the dropdown, by clicking on some of the hyperlink options. The problem is that I can never choose any value.

<select class="form-control" ng-model='obj.animal' id='animal' name='animal'  
    ng-options="opt as opt.animal for opt in aAnimals  track by opt.animal">
          <option style="display:none" value="">Select an animal</option>
</select>

<div ng-repeat='item in aAnimals'>
 <a href='' ng-click='changeval($index)' >{{item.animal}}</a>
</div>

//********controller********//

$scope.obj = {}
$scope.aAnimals=[{ "animal": "cat", "color": "white"},{ "animal": "dog", "color": "black"}]

$scope.changeval=function(index){
  $scope.obj.animal=$scope.aAnimals[index].animal;
}  

http://plnkr.co/edit/8z51qlqfodGSRA1Rv3UH?p=preview

yavg
  • 2,761
  • 7
  • 45
  • 115
  • Possible duplicate of [How to have a default option in Angular.js select box](http://stackoverflow.com/questions/18194255/how-to-have-a-default-option-in-angular-js-select-box) – Sarantis Tofas Dec 27 '16 at 00:25

1 Answers1

2

The options are the items in the array. So you need to change the line to this:

$scope.obj.animal=$scope.aAnimals[index]; // Remove .animal
Hoyen
  • 2,511
  • 1
  • 12
  • 13