angular.js - Angularjs select如何默认选中其中一个option
習慣沉默
習慣沉默 2017-05-15 16:53:32
0
2
619

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);
習慣沉默
習慣沉默

reply all(2)
phpcn_u1582

There are many methods. I personally think the most stable method is:
<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;//如果想要第一个值
世界只因有你

You can consider giving auth_policy.p_info.high_action.action_annex.page a value contained in the content after get

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template