-3

I have this code:

<label ng-repeat="day in days">
    <input type="checkbox" ng-model="activityDays[$index]" /> {{day}}
    <br />
</label>

How can I change text of label when checked?

Dhaval Marthak
  • 17,246
  • 6
  • 46
  • 68
Miha Vidakovic
  • 393
  • 1
  • 4
  • 13

1 Answers1

0

Using JavaScript, you can loop through the input's parent's children, and change its .data if its day.

var checkbox = document.querySelector('input[type=checkbox]');

checkbox.addEventListener('change', function() {
  if (this.checked == true) {
    for (i = 0; i < this.parentNode.childNodes.length; i++) {
      if (this.parentNode.childNodes[i].data !== undefined) {
        if (this.parentNode.childNodes[i].data.trim() == 'day') {
          this.parentNode.childNodes[i].data = 'night'
        }
      }
    }
  } else {
    for (i = 0; i < this.parentNode.childNodes.length; i++) {
      if (this.parentNode.childNodes[i].data !== undefined) {
        if (this.parentNode.childNodes[i].data.trim() == 'night') {
          this.parentNode.childNodes[i].data = 'day'
        }
      }
    }
  }
})
<label ng-repeat="day in days">
  <input type="checkbox" ng-model="activityDays[$index]" />day
  <br />
</label>
Weafs.py
  • 22,731
  • 9
  • 56
  • 78