动态表单未标记为已提交

时间:2016-03-22 14:15:52

标签: javascript angularjs angularjs-ng-form

我有一个包含表格的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属性。

0 个答案:

没有答案