我有一个包含表格的ng-repeat:
<form name="wrapperForm">
<div ng-repeat="thing in things track by $index">
<ng-form name="myForm{{$index}}">
<input type="text" ng-model="thing.name" required />
<span ng-show="myForm{{$index}}.$submitted">Form submitted!</span>
<button type="button" ng-click="doSubmit($index)" />
</ng-form>
</div>
</form>
在控制器中
$scope.doSubmit = function(index) {
var form = $scope.wrapperForm['myForm' + index];
form.$setSubmitted();
}
无论出于何种原因,$setSubmitted
不做任何事情,也不会更改表单的$submitted
属性。