这是文件js中的代码
$scope.ListOption = [];
$scope.ListOption.push({ Value: "0", Name: Car });
$scope.ListOption.push({ Value: "1", Name: House });
以下是代码HTML的样子
<select class="form-control" id="Category" ng-model="Category">
<option ng-repeat="option in ListOption" value="{{option.Value}}">
{{option.Name}}</option>
</select>
生成的html是
<select class="form-control ng-pristine ng-valid" ng-model="Category" style="padding: 0px;">
<option value="? object:null ?"></option>
<option ng-repeat="option in ListOption" value="0" class="ng-binding ng-scope">Car</option>
<option ng-repeat="option in ListOption" value="1" class="ng-binding ng-scope">House</option>
</select>
我在这个问题上非常头疼。期待有人帮助我。
答案 0 :(得分:1)
这是错的。您正在与option
匹配。更改。我建议,使用track by $index
进行无重复选项
<option value="{{option.Value}}" ng-repeat="option in ListOption track by $index">
{{option.Name}}
</option>
答案 1 :(得分:1)
我认为错误在于你使用main数组来获取值而不是iterable选项对象。实际上,这应该有效:
<select class="form-control" id="Category" ng-model="Category">
<option ng-repeat="option in ListOption" value="{{option.Value}}">
{{option.Name}}
</option>
</select>
答案 2 :(得分:1)
希望这是有帮助的:)“
<select class="form-control" data-ng-options="list.Name for list in ListOption" data-ng-model="selectedValue">
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http, $log) {
$scope.ListOption = [];
$scope.ListOption.push({ Value: "0", Name: "Car" });
$scope.ListOption.push({ Value: "1", Name: "House" });
$scope.selectedValue = [];
$scope.selectedValue = $scope.ListOption[0];
});