S.L. Chandrasinghe
S.L. Chandrasinghe

Reputation: 11

How to set AngularJS drop down default value

my HTML code for drop down like follow:

 <select ng-model="selected_value" 
     ng-options="(x.version + ' ' + ' : ' + x.status) for x in allData"></select>

my Angular code like follow : data comes from a rest service

$http.get(......).success(function (data, status){
   $scope.allData = data;
   $scope.selected_value = $scope.allData[0].version + " : " + $scope.allData[0].status;
});

Data comes to the drop down. but initially drop down does not display the value. It shows if only select the value. Can someone help on this issue.

Upvotes: 0

Views: 57

Answers (1)

Ajay Kumar
Ajay Kumar

Reputation: 1164

Add ng-selected="selected_value" to the select element.

An example of what you are trying to achieve can be found in the ngSelected documentation.

Upvotes: 0

Related Questions