我在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
?
答案 0 :(得分:0)
我可以给出一个我没有测试过的解决方法。您需要将创建的表单推送到父作用域的数组中。表格html上的ng-init
可用于我认为
<form class="familyMemberEdit" name="familyMemberEdit_{{ member.spid }}" novalidate ng-init="addForm(this['familyMemberEdit_'+member.spid])">
在控制器上
$scope.addForm=function(form) {
forms.add(form);
}
.