我似乎無法讓這個空白選項消失。有關如何做的建議? AngularJS沒有給我任何有用的信息,我嘗試了很多來自Stackoverflow的建議。這段代碼中出現了什麼是空白選項?
angular.module("myApp", []);
angular.module("myApp").component("app", {
template: `
<div>
<select
ng-model="$ctrl.foo"
ng-options="day.value as day.label for day in $ctrl.days track by day.value"
></select>
</div>
`,
controller: function() {
this.days = _.range(0, 31).map(function(day) {
if (day === 0) return {label: "No Wait", value: day};
return {label: "" + day, value: day};
});
this.foo = 2;
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
<script src="https://code.angularjs.org/1.6.5/angular.js"></script>
<body ng-app="myApp">
<app></app>
</body>
不要以爲你可以擺脫它,請參閱[爲什麼AngularJS包括選擇空選項?](https://stackoverflow.com/questions/12654631/why-does-angularjs-include-an-empty-option-in-select) – user2718281
更改'''this.foo = 2;'' 'to this'''this.foo = {value:2};''' –
[爲什麼AngularJS在select中包含一個空選項?](https://stackoverflow.com/questions/12654631/why -does-angularjs-include-an-empty-option-in-select) –