angularjs中下拉框select option默认值

时间:2024-01-05 08:43:44

1.问题说明:

option ng-repeat多空白项

2.解决方案:

html:

<ion-view hide-nav-bar="true">
<ion-content>
<div class="list card">
<div>
<label class="item item-input item-select">
<div class="input-label">
<span>安排类型</span>
</div>
<select
ng-change="selectAction()"
ng-model="selectedType.value"
ng-init="selectedType.value = ''"
>
<option value="">-- 请选择 --</option>
<option
ng-repeat="item in workArrangeTypes"
value="{{item.value}}"
>{{item.name}}</option>
</select>
</label>
</div>
<div class="item">
<button style="width: 100%;" class="button button-positive" ng-click="submitWork()">提交安排工作</button>
</div>
</div>
</ion-content>
</ion-view>

js:

/************************************** 区域管理 *************************************/
.controller('RegionalManageCtrl', ['$scope',function($scope) {
/*** 测试 ***/
$scope.selectedType = {value: 1}; // 默认值
$scope.workArrangeTypes = [
{name: '社区服务', value: 1},
{name: '教育学习', value: 2},
{name: '思想汇报', value: 3},
{name: '电话汇报', value: 4},
{name: '家庭访问', value: 5}
]; // 工作安排类型 // 每次option改变时自动调用该方法
$scope.selectAction = function() {
console.log($scope.selectedType.value); // 5
} /**
* 提交工作安排
*/
$scope.submitWork = function() {
console.log($scope.selectedType); // {value: 5}
}
}])

3.效果图

angularjs中下拉框select option默认值