Home>

In the past two days, I encountered a problem that the initial value was blank during the process of using ng-options.I remember encountering it last year,I forgot how to solve it,Solved it after a while,Want to write it down,Convenient friends who encounter the same problem, of course, have their own.

1. Scenario:

Is to make a popup of a query list,One of the conditions requires the use of a drop-down menu.The data is passed through Ajax.

2. Realize:

a.html:

<select ng-model="myselect" ng-options="o for o in options"></select>

b.js:

var url="xxxxxx";//The url is just an example,The specific code is to write the available request address.
$http.post (url).
       success (functoin (data) {
        $sope.options=data;//Assign to ng-options
      });

I thought then,The html is written, and the dynamic data is passed to ng-options, so that the drop-down menu can be used.After running it is generally normal,Just the drop-down menu is blank,The data passed in the background appears after clicking,There is the first blank item,Click to pop up all the drop-down options,After selecting the options i want to select,The blank items disappear again.

Looking at the loaded html in the browser, it is found that there is an option that is not passed in the background in the