0

我在 ng-repeat 中生成了几种形式:

<div class="familyMembers" data-ng-repeat="member in familyMembers">
    ...
    <form class="familyMemberEdit" name="familyMemberEdit_{{ member.spid }}" novalidate>
    ...
    </form>
    ...
</div>

在相应的控制器中,我想在每个表单上检查 $dirty:

...
var a = '';
var condition = false;
angular.forEach($scope.familyMembers, function(value, key) {
    a = 'familyMemberEdit_' + value.spid;
    condition = condition || $scope[a].$dirty;
});
return condition;

$scope[a]退货undefined。在这种情况下我应该如何参考$scope.familyMemberEdit_1234

4

1 回答 1

0

我可以给出一个我没有测试过的解决方法。您需要将创建的表单推送到父范围上的数组中。ng-init我认为可以在表单上使用 html

 <form class="familyMemberEdit" name="familyMemberEdit_{{ member.spid }}" novalidate ng-init="addForm(this['familyMemberEdit_'+member.spid])">

在控制器上

$scope.addForm=function(form) {
    forms.add(form);
}
.
于 2013-10-09T09:56:49.343 回答