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

1

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.