Ng-change does not work after clicking on each switch in the list

I am creating a small application for my project in college, I have a scenario where the user clicks on the switch, the event should be fired.

My Angular Code:

<div ng-repeat="q in questionList " ng-if="ExamOver == false">
      <h2>{{count+1}} .{{q.questionText}}</h2>
      <ul>
          <li ng-repeat="d in q.Choices">
              <input type="radio" name="isCorrect" ng-model="correctAnswer.isworking" ng-change="getDetails($index,d,correctAnswer.isCorrect);" value="Yes" />
              {{d.choiceText}}
          </li>
     </ul>
</div>

In my controller, I have this code:

$scope.correctAnswer = {isCorrect : false};

$scope.getDetails = function (index, choiceList, isCorrect) {    
    /* some logic... */
}

Events fire only once per button, I try to get around this in the last few hours without any progress, can someone please direct me, what am I doing wrong here?

+4
source share
2 answers

ng-change , ( ng-model) , value="Yes". ng-change . docs:

, . , JavaScript onchange , (, ).

, :

1

:

<li ng-repeat="d in q.Choices">
     <input type="radio" 
            name="isCorrect" 
            ng-model="correctAnswer.isworking" 
            ng-change="getDetails($index, d, correctAnswer.isCorrect)" 
            ng-value="$index" />
     {{d.choiceText}}
</li>

2

, :

ng-click="getDetails($index, d, correctAnswer.isCorrect)"
+7

ngChange , ngModel.

, ""

<input type="radio" name="isCorrect" ng-model="..." ng-change="..." value="Yes" >
+1

Source: https://habr.com/ru/post/1675675/


All Articles