[英]The default value is not ? object:null ? in select option Angularjs
This is code in file js 这是文件js中的代码
$scope.ListOption = [];
$scope.ListOption.push({ Value: "0", Name: Car });
$scope.ListOption.push({ Value: "1", Name: House });
Here's what the code HTML looks like 这是HTML代码的样子
<select class="form-control" id="Category" ng-model="Category">
<option ng-repeat="option in ListOption" value="{{option.Value}}">
{{option.Name}}</option>
</select>
The generated html is 生成的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>
I have quite a headache on this issue. 在这个问题上我很头疼。 Looking forward to having someone help me the other way.
期待有人帮助我。
it's wrong. 这是不对的。 you are matching with
option
. 您与
option
匹配。 Change it. 更改。 I suggest, use the
track by $index
for no repeat options 我建议不要重复使用
track by $index
的track by $index
<option value="{{option.Value}}" ng-repeat="option in ListOption track by $index">
{{option.Name}}
</option>
I think the mistake is that you used the main array to get value instead of iterable option object. 我认为错误是您使用主数组获取值而不是可迭代的选项对象。 Actually, this should work:
实际上,这应该起作用:
<select class="form-control" id="Category" ng-model="Category">
<option ng-repeat="option in ListOption" value="{{option.Value}}">
{{option.Name}}
</option>
</select>
Hope this is helpfull :) 希望这对您有所帮助:)
<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];
}); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.