爲什麼AngularJS在select中包含一個空選項? - Why does AngularJS include an empty option in select?

問題:

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
參考二: Why does AngularJS include an empty option in select?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章