简体   繁体   中英

How select an item from dropdown list in angularjs?

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>

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
});

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 ie

JSONResponse = {"range" : "100"}

html:

<select class="form-control" ng-model="ModelValues.range" ng-change="updateRange()">
</select >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM