ng-options how to set first select always blank

前端 未结 8 2097
耶瑟儿~
耶瑟儿~ 2020-12-05 12:44

I am using angularjs in a project and in which I am using ng-options for generating .

Initially when the pages reload and no option element is selected the html gene

相关标签:
8条回答
  • 2020-12-05 13:24

    You can forgo using the ng-options and use ng-repeat instead and make the first option blank. See example below.

    <select size="3" ng-model="item">
        <option value="?" selected="selected"></option>
        <option ng-repeat="s in itemlist" value="{{s.value}}">{{s.name}}</option>
    </select>
    
    0 讨论(0)
  • 2020-12-05 13:30

    I had same problem and after a lot of googling,I understood the main issue was related to my angular version, if you use Angular 1.6.x, just use the ng-value directive and it will work as expected.

    also I set an initial value in my controller, like this :

    $scope.item = 0;
    
    0 讨论(0)
提交回复
热议问题