AngularJS无线电集团不设现场$脏 [英] AngularJS Radio group not setting $dirty on field
问题描述
我试图用角的$脏标志的形式提交仅将更改的领域。
I'm trying to use Angular's $dirty flag to submit only the changed fields in a form.
当我跑进单选按钮组,我是缺少改变字段列表的变化。我有一个小提琴重现我看到的问题。
When I ran into radio button groups, I was missing the changes in the list of changed fields. I have a fiddle that reproduces the problem I am seeing.
<div ng-app="form-example" ng-controller="MainCtrl">
<form name="form" novalidate>
<input type="radio" name="myRadio" ng-model="myRadio" value="one" required>One<br />
<input type="radio" name="myRadio" ng-model="myRadio" value="two" required>Two<br />
<input type="radio" name="myRadio" ng-model="myRadio" value="three" required>Three<br />
<input type="radio" name="myRadio" ng-model="myRadio" value="four" required>Four<br />
<input type="radio" name="myRadio" ng-model="myRadio" value="five" required>Five<br /><br />
Form $dirty: {{form.$dirty}}<br />
Field $dirty: {{form.myRadio.$dirty}}<br />
Value: {{myRadio}}
</form>
</div>
单击最后一个单选按钮时的
字段的$脏标志将只更改即使窗体$脏更新正确。
The field's $dirty flag will only change when the last radio button is clicked even though the form $dirty updates properly.
我在这里丢失一些基本的东西?而且是有此行为的解决方法吗?
Am I missing something fundamental here? and is there a workaround for this behavior?
推荐答案
每个 NG-模型
实际上实例化一个控制器。
当你点击任何单选按钮,控制器会将 $脏
字段设置为真正
并设置形式。$脏
为true。
Each ng-model
actually instantiates a controller.
When you click any radio button, the controller sets $dirty
field to true
and sets form.$dirty
to true.
问题是, form.myRadio
持有参照最后单选按钮的模型
作为一种变通方法,您可以使用嵌套表格与 NG-形式
。在这里看到: http://jsfiddle.net/UM578/
As a workaround you can use nested forms with ng-form
. See here: http://jsfiddle.net/UM578/
这篇关于AngularJS无线电集团不设现场$脏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!