-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
  • 16,632
  • 6
  • 39
  • 66
Miha Vidakovic
  • 341
  • 1
  • 3
  • 12

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
  • 21,559
  • 8
  • 48
  • 73