0
感謝您閱讀我的問題。我知道有類似的問題,但我沒有解決我的問題,所以我發佈了我的問題。我想通過點擊一些超鏈接選項來爲下拉列表分配一個值。問題是我永遠不能選擇任何價值。在angular.js中選擇一個默認選項ng-option
<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
的可能的複製[如何在Angular.js選擇框中默認選項](http://stackoverflow.com/questions/18194255/how-to-具有-A-默認選項功能於角JS-選擇盒) – Akis