mardi 28 juin 2016

ng-checked not updating first time

I'm generating check boxes using ng-repeat, and their initial status can be checked or unchecked depending on if that information exists or not in the data. My problem is that altghough it shows their initial checked/unchecked status correctly, when I uncheck a box that has been 'pre-checked', the box physically unchecks but the model doesn't change. Then I check it again, and the model doesn't change but it's correct. Then I uncheck again, and it clears correctly in the model and works correctly from then on. I have been working on this problem for days and I'm totally stuck! Can anyone see if I'm doing something stupid? My feeling is that it's an initialisation problem but I'm too close to it to see now. Thanks!

<!-- if this is a checkbox to be drawn -->
<div ng-if="option.option_type=='checkbox'">
  <label class="item-checkbox-right">
   
   <!-- handle multiple options -->

  <!-- if answered_options[n]weight exists, make option.ans = weight --></label>
  <ul ng-repeat="opti in questionpart.survey_answer[0].answered_options">
    <li style="list-style: none; display: inline">

    <!-- if option is set in the received data, set it in the model -->
      <div ng-if="opti.id == option.id">
        <div ng-init="option.ans = option.weight"></div>
      </div>
    </li>
  </ul>
  <label class="item-checkbox-right">
      <!-- show the checkbox and bind to option.ans-->
      <input class="checkbox-light" 
      type="checkbox" 
      name="" 
      ng-false-value="0" 
      ng-true-value=""
      ng-model="option.ans"
      ng-checked="option.ans==option.weight" />
  </label>
</div>




Aucun commentaire:

Enregistrer un commentaire