我有一个ng-repeat
功能,其中显示3个输入文本框。但是理智按钮似乎应用了验证(我需要启用'保存'按钮仅当我填写所有三个输入)
<form name="myForm" novalidate>
<div ng-repeat="item in items">
<input type="text" ng-model=item.name required class="form-control">
</div>
</form>
<button type="button" ng-disabled="myForm.$invalid" ng-click="save()">Save</button>
控制器:
$scope.items=[{
id:1,
name:VALUE1
},{
id:2,
name:VALUE2
},{
id:3,
name:VALUE3
}]
答案 0 :(得分:2)
您的代码似乎工作正常。只需知道如果您的模型为空,则会禁用该按钮: -
<div ng-controller="MyCtrl">
<form name="myForm" novalidate>
<div ng-repeat="item in items">
<input type="text" ng-model=item.name required class="form-control">
</div>
</form>
<button type="button" ng-disabled="myForm.$invalid" ng-click="save()">Save</button>
</div>
function MyCtrl($scope) {
$scope.items=[{
id:1,
name:"VALUE1"
},{
id:2,
name:"VALUE2"
},{
id:3,
name:""
}]
}