Luí*_*ota 3 angularjs angularjs-ng-model
我有一个包含大约100个问题的表单,每个表单都有一个收音机和一些复选框,因此我需要用户能够保存表单并在以后加载它.我还需要检查用户在此会话中更改了哪些内容.
这个问题解决了这个问题:我怎样才能表示AngularJS中哪些输入字段已经改变
第二个答案(存储模型的旧值和当前值并比较两者)就可以了.但是,如果我想使用$ pristine解决方案,我有一个问题.取消选中ng-checked框不会改变它的$ pristine值.取消选中后,再次选中该复选框,$ pristine值将变为false.
我知道我不习惯使用带有ng-check的ng-model但是我从服务器得到的值为1或0.这个用作模型的值不检查复选框.
ng-model="question.answer" //will not check the box
ng-check="question.answer" //does check the box
Run Code Online (Sandbox Code Playgroud)
服务器的值为1.取消选中并选中此复选框会将其更改为"true"
<input ng-model="question.answer" ng-checked="question.answer"
type="checkbox" name="{{'answer' + question.id}}"/>
Run Code Online (Sandbox Code Playgroud)
继承人:http://plnkr.co/edit/3xcI0Yq9WPZ1IxJJjKGt?p =preview
您需要的是分别设置1和0被视为真值和假值.您可以使用ng-true-value和ng-false-value设置该设置.你不必处理将1/0转换为true/false,也可以有效地摆脱ng-checked和使用ng-model自己.
<input ng-model="question.answer"
ng-true-value="1"
ng-false-value="0" type="checkbox" name="{{'answer' + question.id}}" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3329 次 |
| 最近记录: |