我似乎无法让这个空白选项消失。有关如何做的建议? 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) –