Answers for "Angular - dynamically set model property of object bound to radio button based on its state"

0

Angular - dynamically set model property of object bound to radio button based on its state

function setTrueFalseRadioState(answer) {
     angular.forEach(vm.files, function (a) {
        if (a.IsMyChoice !== answer.IsMyChoice) {
            a.IsMyChoice = false;
        }
     });
 };

 vm.setTrueFalseRadioState = setTrueFalseRadioState;


I discovered that if you want to send the object data to the backend server, you need to set the ng-value to its index
  
  <input type="radio"
         id="isChoice_{{$index + 1}}"
         name="response"
         ng-value="{{$index + 1}}"
         ng-required="!file.IsMyChoice"
         ng-change="get.setTrueFalseRadioState(file)"
         data-ng-model="file.IsMyChoice" />

and the use javascript to check the values like:

  if (file.IsMyChoice !== undefined) {
     file.IsMyChoice !== false ?
     file.IsMyChoice = 'true' : file.IsMyChoice = 'false';
  }
Posted by: Guest on May-26-2020

Code answers related to "Angular - dynamically set model property of object bound to radio button based on its state"

Code answers related to "Javascript"

Browse Popular Code Answers by Language