AngularJS: $ net for ng-check checked inputs

I have a form with about 100 questions, each with a radio and some checkboxes, so I need the user to be able to save the form and load it later. I also need to check which ones the user has changed in this session.

This question solves the problem: How can I tell which input fields have changed in AngularJS

The second answer (keeping the old and current values ​​of the model and comparing both) does it. However, if I wanted to go with an untouched solution, I got a problem. Removing the ng-check checkbox will not change the value of $ pristine. The $ original value becomes false only after checking the checkbox after unchecking.

I know that I cannot use ng-model with ng-check, but I get responses from the server in values ​​of 1 or 0. These values ​​used as a model do not check the checkboxes.

ng-model="question.answer"  //will not check the box
ng-check="question.answer"  //does check the box

      

The value comes as 1 from the server. Unchecking and checking the checkbox changes it to "true"

<input ng-model="question.answer" ng-checked="question.answer" 
type="checkbox" name="{{'answer' + question.id}}"/>

      

Heres a plnkr: http://plnkr.co/edit/3xcI0Yq9WPZ1IxJJjKGt?p=preview

+3


source to share


1 answer


You need to install 1

and 0

how true and false values, respectively. You can use and to adjust. You don't need to deal with converting 1/0 to true / false and can also get rid of and use effectively . ng-true-value

ng-false-value

ng-checked

ng-model

<input ng-model="question.answer" 
            ng-true-value="1" 
            ng-false-value="0" type="checkbox" name="{{'answer' + question.id}}" />

      



Plnkr

+5


source







All Articles