html程式碼為,如果ng-model的值在InPageSel裡有的話,介面上是選取的。但如果沒有,介面上選擇的是空白欄,介面下拉內容很多,希望能做到預設選第一個。
<select ng-model="auth_policy.p_info.high_action.action_annex.page" ng-options="en as en for en in InPageSel" style="width:150px;"></select>
js程式碼,select資料是從後台get過來然後放在InPageSel陣列裡的
$scope.InPageSel = [];
angular.forEach(data_select.script_pagelist,function(v,k){
this.push(v.page_name);
},$scope.InPageSel);
phpcn_u15822017-05-15 16:55:32
方法有很多種,個人認為最穩定的方法是:<select ng-model="selected" ng-options="x.id as x.name for x in users"></select>
js
$scope.users = [ {name:'a',id:'1'}, {name:'b',id:'2'}, {name:'c',id:'3'} ]; $scope.selected='2';//id的值,区分类型 $scope.selected=$scope.users[0].id;//如果想要第一个值