问题:
I've been working with AngularJS for the last few weeks, and the one thing which is really bothering me is that even after trying all permutations or the configuration defined in the specification at http://docs.angularjs.org/api/ng.directive:select , I still get an empty option as the first child of select element. 在过去的几周里,我一直在使用AngularJS,而令我困扰的一件事是,即使尝试了所有置换或http://docs.angularjs.org/api/ng规范中定义的配置, .directive:select ,我仍然得到一个空选项作为select元素的第一个子元素。
Here's the Jade: 这是玉:
select.span9(ng-model='form.type', required, ng-options='option.value as option.name for option in typeOptions');
Here the controller: 这里的控制器:
$scope.typeOptions = [
{ name: 'Feature', value: 'feature' },
{ name: 'Bug', value: 'bug' },
{ name: 'Enhancement', value: 'enhancement' }
];
Finally, here's the HTML which gets generated: 最后,这是生成的HTML:
<select ng-model="form.type" required="required" ng-options="option.value as option.name for option in typeOptions" class="span9 ng-pristine ng-invalid ng-invalid-required">
<option value="?" selected="selected"></option>
<option value="0">Feature</option>
<option value="1">Bug</option>
<option value="2">Enhancement</option>
</select>
What do I need to do to get rid of it? 我需要怎么做才能摆脱它?
PS: Things work without this as well, but it just looks odd if you use select2 without multiple selection. PS:事情也不需要这样做,但是如果您使用select2而不进行多重选择,那看起来就很奇怪。
解决方案:
参考一: https://stackoom.com/question/r62x/为什么AngularJS在select中包含一个空选项参考二: https://oldbug.net/q/r62x/Why-does-AngularJS-include-an-empty-option-in-select
来源:oschina
链接:https://my.oschina.net/stackoom/blog/4355748