javascript - Dynamically creating radio buttons and selected appropriate button Angularjs -
i have questionnaire form loops on questions , answers in questions , creates radio buttons answers. answer object have property of answered either true or false depending on whether or not answer had been selected item. if answer.answered = true, radio button should checked(only 1 have been answered). problem is can not appropriate radio button checked based on answer.answered. have tried ng-value="answer.answered", setting model on init. abbreviated code below.
<md-card data-ng-repeat="question in gradectrl.questions | limitto: 1 track $index" class="questions main-questions" data-ng-if="!gradectrl.subquestions && gradectrl.needsrepairs === false"> <ul data-ng-repeat="answer in question.answers track $index" class="questionnaire" layout-wrap layout="column" layout-align="center center"> <li> <input type="radio" name="{{question.id}}" data-ng-attr-id="answer.id" data-ng-value="gradectrl.isanswered(answer);" data-ng-init="gradectrl.radiobutton[answer.id]=gradectrl.isanswered(answer);" data-ng-model="gradectrl.radiobutton[answer.id]"> </li> </md-card>
i able solve setting model = answer.answered using ng-checked.
<input type="radio" name="{{question.id}}" data-ng-checked="gradectrl.isanswered(answer);" data-ng-attr-id="answer.id" data-ng-init="gradectrl.radiobutton[answer.id] = gradectrl.isanswered(answer);" data-ng-click="gradectrl.saveanswer(answer, question.question)" data-ng-model="answer.answered">
Comments
Post a Comment