Reputation: 2379
How select an item from dropdown list in angularjs,Here I am using normal select list but not from object array.
If I am using ng-repeat then I can select one,
but here how can I do the same?
<select class="form-control" ng-model="range" ng-change="updateRange()">
<optgroup label="Current">
<option value="1.1">Today</option>
<option value="1.2">This Week</option>
<option value="1.3">This Month</option>
<option value="1.4">This Quarter</option>
<option value="1.5">This Year</option>
</optgroup>
<optgroup label="Previous">
<option value="2.1">Yesterday</option>
<option value="2.2">Previous Week</option>
<option value="2.3">Previous Month</option>
<option value="2.4">Previous Quarter</option>
<option value="2.5">Previous Year</option>
</optgroup>
<optgroup label="Custom">
<option ng-value="3">Custom</option>
</optgroup>
</select>
Upvotes: 4
Views: 1082
Reputation: 4066
Try to put your model data in form of an array :
In your controller
$scope.ModelValues = JSONResponse;
JSON Response should contain the value to be selected in the drop down i.e
JSONResponse = {"range" : "100"}
html:
<select class="form-control" ng-model="ModelValues.range" ng-change="updateRange()">
</select >
Upvotes: 1
Reputation: 8465
Simply assign value to the model that corresponds with option
value
http://plnkr.co/edit/bB4Y8aOufk9UL3oRRHD7?p=preview
app.controller('MainCtrl', function($scope) {
$scope.range = 2.4
});
Upvotes: 2