第一个解决方案,您可以为默认值添加一个选项标签
html代码
<div ng-app="MyApp">
<div ng-controller="MyCtrl">
<select ng-options="opt as opt for opt in testOpt"
data-ng-model="resultOpt"
data-ng-change="checkResultOpt(resultOpt)">
<option value=''>Choose Category </option>
</select>
</div>
</div>
控制器代码
var MyApp = angular.module('MyApp', [])
.controller('MyCtrl', ['$scope', function ($scope) {
$scope.testOpt = [
'ID',
'Name',
'Email',
'Address'
];
$scope.resultOpt = '';
}]);
工作代码
第二种解决方案:从 http 调用获取后,您只需在数组列表中添加一项
html代码
<div ng-app="MyApp">
<div ng-controller="MyCtrl">
<select ng-options="opt as opt for opt in testOpt"
data-ng-model="resultOpt"
data-ng-change="checkResultOpt(resultOpt)">
</select>
</div>
</div>
控制器代码:
var MyApp = angular.module('MyApp', [])
.controller('MyCtrl', ['$scope', function ($scope) {
$scope.testOpt = [
'ID',
'Name',
'Email',
'Address'
];
$scope.testOpt.splice(0, 0, 'Choose Category');
$scope.resultOpt = 'Choose Category';
}]);
工作代码
希望对你有帮助