这是选择框
<form name="permissionForm" novalidate>
<select ng-model="permissionForm.homePostPermission" name="permissionHomePage" ng-options="permission.name for permission in permissions" required>
</select>
<div ng-show="permissionFormErrorShowTag">
<div ng-show="permissionForm.permissionHomePage.$error.required">Required</div>
</div>
</form>
这是控制器代码
//setting the values of permission
$scope.permissions = [{'name':'Public','value':'1'},{'name':'Friend','value':'2'},{'name':'Only me','value':'3'}];
$scope.permissionForm = {};
$scope.permissionForm.homePostPermission = $scope.permissions[0].value;
空白选项仍显示在选项中。不能丢弃它。请帮助我。
添加了这个小提琴
http://jsfiddle.net/MTfRD/2957/
感谢您的时间
答案 0 :(得分:1)
试试这个。更改表单名称。以及使用对象的init模型。
pause -1
var app = angular.module("app", []);
app.controller('mainCtrl', function($scope){
$scope.permissions = [{'name':'Public','value':'1'},{'name':'Friend','value':'2'},{'name':'Only me','value':'3'}];
$scope.permissionForm = {};
$scope.permissionForm.homePostPermission = $scope.permissions[0];
});
答案 1 :(得分:0)
您必须在ng-options中按 permision.value 添加曲目,如下所示:
<select class="form-control" ng-model="permissionForm.homePostPermission" name="permissionHomePage" ng-options="permission.name for permission in permissions track by permision.value" required=""></select>
你完成了!祝你好运:))
Plunker输出: