javascript - ng-options sets the default option, not the first one, see clearly!
天蓬老师
天蓬老师 2017-07-04 13:44:50
0
2
1134

I used ng-options to write a drop-down selection box. Now the problem is to make the default selection function, not to select the first one by default! The default selection is set based on other parameters (my idea)! I don't have any ideas in my head right now, so I'm posting this for everyone to see and help - thank you!

html code screenshot:

Data source screenshot:

Screenshot of page effect:

Additional: Because this project is done using ng, I can get the name of the current department deparrment_name on the html page through other methods, but how can I use this department name to make the default selection in the drop-down selection! ?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all (2)
phpcn_u1582

Html code

js code

$scope.selectData = data source;
$scope.currSelect = $scope.selectData[0]; Here you want to set the default index, just use the
ng-change event, if you don’t need to operate other objects , you don’t need to write it, if you choose other options, your ng-model will also change

    某草草

    Because you are using the nativeis selected by default, as long as thevalueofcan set the currently selected.

    So, in Angular, you only need to modify the bound value (that is, the corresponding value of yourv-modelcurrSelect), and set it to the corresponding value of the second itemvalueselectData[1] .idcan be the same.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!