【发布时间】:2016-06-14 23:13:39
【问题描述】:
我在尝试更新我的父 ngForm 状态时遇到了一些问题;当它的所有孩子都被清理并设置为“Pristine”时,它应该设置为“Pristine”......但这似乎不会自动发生。
我在这里创建了一个 plunk 来更好地解释这个问题:http://plnkr.co/edit/vCX7ltOb8fgl3fkEpvzy?p=preview
<body ng-controller="MainCtrl">
<div ng-form="parentForm1" class="parent-form">
parentForm1.dirty: <b>{{parentForm1.$dirty}}</b>
<form name="childForm1" class="child-form" novalidate>
childForm1.dirty: <b>{{childForm1.$dirty}}</b>
<br/>
<input type="text" ng-model="field1">
<br/>
<button ng-click="reset1()">Clean and setPristine</button>
</form>
<form name="childForm2" class="child-form" novalidate>
childForm2.dirty: <b>{{childForm2.$dirty}}</b>
<br/>
<input type="text" ng-model="field2">
<br/>
<button ng-click="reset2()">Clean and setPristine</button>
</form>
</div>
</body>
我哪里错了?我找到了使用外部模块的解决方案...我想用尽可能少的代码来解决它(也许是指令?)。
【问题讨论】:
-
我想你找到了你自己的答案,用'angular-input-modified'!请添加解决方案并将其标记为已回答,以便与社区分享。
标签: angularjs angularjs-ng-form