AngularJS - extra blank option added using ng-repeat in select tag

前端 未结 3 1754
遇见更好的自我
遇见更好的自我 2020-12-08 18:32

I have a listbox that I am creating with a select, using AngularJS ng-repeat. The listbox is created correctly, and when I select one of the items and click my button, I ge

3条回答
  •  忘掉有多难
    2020-12-08 19:28

    Any time you see in the select, it means that your ng-model is set to a value that isn't in the ng-options. So, if you don't want the blank option, you need to make sure item is set to a value in your itemlist. This could be as easy as having the following in your controller:

    $scope.item = $scope.itemlist[0];
    

    This will give it an inital value, and then angular will update it for you thereafter.

提交回复
热议问题