search

Home  >  Q&A  >  body text

angular.js - How to select one of the options by default in Angularjs select

The html code is, if the value of ng-model exists in InPageSel, it will be selected on the interface. But if not, the blank column is selected on the interface. There are many drop-down contents on the interface. I hope the first one can be selected by default.

1

2

<code><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>

</code>

js code, the select data is obtained from the background and placed in the InPageSel array

1

2

3

4

5

<code>$scope.InPageSel = [];

angular.forEach(data_select.script_pagelist,function(v,k){

this.push(v.page_name);

},$scope.InPageSel);

</code>

習慣沉默習慣沉默2904 days ago697

reply all(2)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-15 16:55:32

    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>

    1

    2

    3

    4

    5

    6

    7

    8

    <code>js</code><code>$scope.users = [

            {name:'a',id:'1'},

            {name:'b',id:'2'},

            {name:'c',id:'3'}

        ];

        $scope.selected='2';//id的值,区分类型

        $scope.selected=$scope.users[0].id;//如果想要第一个值

    </code>

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-15 16:55:32

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

    reply
    0
  • Cancelreply