The dom result is as follows, which is a drop-down list for height selection
<select ng-model="selectedHeight" ng-options="obj.h for obj in heights"></select>
Pass a height array to heights in the controller
$scope.heights=[{"h":"140cm"},{"h":"141cm"}];
During initialization, the drop-down list needs to display the first 140cm option. How can I display the first option?
Exploration:
In the current situation, it is useless to use $scope.selectedMonth = $scope.months[0].value; directly. We need to add a value to the array
$scope.heights=[{"h":"140cm","value":0},{"h":"141cm","value":1}];
At the same time, during two-way binding, bind the value in
<select ng-model="selectedMonth" ng-options="obj.value as obj.h for obj in heights"></select>
In this case, you can initialize the display
$scope.selectedMonth = $scope.months[0].value;
<select ng-model="selectedMonth" ng-options="obj as obj.h for obj in heights"></select>
Reference:
Link Description
Initialize in controller: