Search code examples
angularjscheckboxhref

how do i link a checkbox to a website


I have the following code:

<input type="checkbox" id="{{ day.name }}-{{ $index }}" ng-model="slot.booked" ng-disabled="slot.booked">
        <label for="{{ day.name }}-{{ $index }}">{{ slot.time }}<br>
          <span ng-if="slot.booked">Booked</span>
          <span ng-if="!slot.booked">Available</span>
        </label>

Is there anyway that I can make it so that when the checkbox in clicked, it takes the user to another site?


Solution

  • Another approach would be to use the ngChange directive

    <input type="checkbox" ng-model="confirmed" ng-change="change()" />
    

    And in the controller:

     $scope.change = function() {
       //opens a new tab in browser
       window.open('http://stackoverflow.com/questions/35686170/how-do-i-link-a-checkbox-to-a-website', '_blank');
    }
    

    Working fiddle